图书网上商城实现(一)

一、角色和功能

  • 用户:
    • 登录
    • 浏览图书信息
    • 添加商品到购物车
    • 下订单
    • 支付。
  • 管理员:
    • 登录
    • 管理用户信息
    • 管理商品。

二、表设计

实体(Entity):图书表(t_book)、用户表(t_user)、管理员表(t_admin)、图书类别表(t_category)

关联(Relation):用户订单关联表(t_order)、订单图书关联表(t_order_item)

三、搭建基于SpringBoot的Web开发框架

1、新建maven项目

2、引入spring boot的相关依赖包

在pom.xml中加入


    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.5.10.RELEASE</version>
    </parent>
    <dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-thymeleaf</artifactId>
    </dependency>
        <dependency>
            <groupId>org.apache.shiro</groupId>
            <artifactId>shiro-spring</artifactId>
            <version>1.4.0</version>
        </dependency>
        <dependency>
            <groupId>org.apache.shiro</groupId>
            <artifactId>shiro-core</artifactId>
            <version>1.4.0</version>
        </dependency>
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-lang3</artifactId>
            <version>3.7</version>
        </dependency>
        <!-- Test -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>
    

3、加入配置文件

在resource文件夹下新建application.properties文件,文件中加入


spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/shop?useUnicode=true&amp;characterEncoding=utf-8
spring.datasource.username=root
spring.datasource.password=root

spring.jpa.properties.hibernate.hbm2ddl.auto=validate
spring.h2.console.enabled=true
spring.jpa.open-in-view=true
logging.level.org.hibernate.SQL=debug
spring.jpa.show-sql=true

spring.thymeleaf.cache=false
spring.thymeleaf.content-type=text/html

4、新建包、实体类和Repository

原文地址:https://www.cnblogs.com/gloria-liu/p/8666698.html