1、在pom.xml文件中添加如下所需依赖。
<!-- security -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<!-- thymeleaf -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<!-- mysql -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<!-- security-test -->
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
<scope>test</scope>
</dependency>
<!-- mybatis-plus -->
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.3.1.tmp</version>
</dependency>
<!-- druid -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>1.1.18</version>
</dependency>
2、在application.properties文件中添加如下配置。
#Thymeleaf的相关配置
spring.thymeleaf.prefix=classpath:/templates/
spring.thymeleaf.suffix=.html
spring.thymeleaf.servlet.content-type=text/html
spring.thymeleaf.cache=false
spring.thymeleaf.mode=LEGACYHTML5
spring.thymeleaf.encoding=UTF-8
#服务端口号
server.port=8080
#配置数据库
#配置当前要使用的数据源的操作类型
spring.datasource.type=com.alibaba.druid.pool.DruidDataSource
#配置MySQL的驱动程序类
spring.datasource.driver-class-name= com.mysql.cj.jdbc.Driver
#数据库连接地址
spring.datasource.url=jdbc:mysql://127.0.0.1:3306/mybatis?useUnicode=true&zeroDateTimeBehavior=convertToNull&autoReconnect=true&characterEncoding=utf-8&serverTimezone=GMT
#数据库用户名
spring.datasource.username=root
#数据库连接密码
spring.datasource.password=123456
#数据库连接池的最小维持连接数
spring.datasource.dbcp2.min-idle= 5
#初始化提供的连接数
spring.datasource.dbcp2.initial-size=5
#最大连接数
spring.datasource.dbcp2.max-total=5
#等待连接获取的最大超时时间
spring.datasource.dbcp2.max-wait-millis=200
# 配置mybatis相关路径
mybatis.mapper-locations=classpath:/mapper/*.xml