3 系统管理
3.1 项目相关依赖
除了利用 start.spring.io快速创建基于Thymeleaf的Spring Boot Web应用自带的spring-boot-starter-web、spring-boot-starter-test和spring-boot-starter-thymeleaf依赖外,还需要添加上传文件依赖commons-fileupload、Mybatis与Spring整合依赖mybatis-spring-boot-starter以及MySQL连接器依赖mysql-connector-java。这里的依赖添加下载,使用阿里云仓库:
<repositories>
<repository>
<id>aliyun</id>
<name>aliyun</name>
<url>https://maven.aliyun.com/repository/public</url>
</repository>
</repositories>
具体的pom.xml文件代码如下:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.5.3</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>pers.xsc</groupId>
<artifactId>online_shopping</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>online_shopping</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
</properties>
<repositories>
<repository>
<id>aliyun</id>
<name>aliyun</name>
<url>https://maven.aliyun.com/repository/public</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>2.2.0</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.3.3</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
3.2 项目展示页面与静态资源管理
项目的两个系统页面分开存放,后台页面存放在src/main/resources/templates/admin,前台页面存放在src/main/resources/templates/user;在src/main/resources/static下存放jQuery、css文件。
3.3 项目的目录结构
3.3.1 pers.xsc.online_shopping.controller包
controller包中有两子包:admin和before,存放控制器类。
3.3.2 pers.xsc.online_shopping.entity包
entity包存放实体类。
3.3.3 pers.xsc.online_shopping.exception包
exception包存放统一异常处理类、异常枚举类。
3.3.4 pers.xsc.online_shopping.mapper包
mapper包中有两子包:admin和before,存放的Java接口程序是实现数据库的持久化操作。每个接口方法与SQL映射文件中的id相同。
3.3.5 pers.xsc.online_shopping.service包
service包中有两子包:admin和before,存放业务层的接口与实现类。
3.3.6 pers.xsc.online_shopping.utils包
utils包存放工具类。
3.4 项目配置文件
server.port=8083
spring.datasource.name=imooc_mall_datasource
spring.datasource.url=jdbc:mysql://127.0.0.1:3306/online_shopping?useUnicode=true&characterEncoding=utf8&autoReconnect=true&useSSL=false&serverTimezone=Asia/Shanghai
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.username=root
spring.datasource.password=19980617zqqxsc
#告诉系统去哪里找mapper.xml映射文件
mybatis.mapper-locations=classpath:mappers/*.xml
logging.level.pers.xsc.online_shopping.mapper=debug
spring.thymeleaf.cache=false
spring.servlet.multipart.max-file-size=50MB
spring.servlet.multipart.max-request-size=500MB