One, pom.xml
1. File location
2. Explanation
This file is used to declare the dependencies used. Because it is a springboot project, first add the parent node <parent></parent>. What dependencies we need, just add them in <dependencies> </dependencies>.
Spring boot is also a maven project, and the method of introducing dependencies is the same. See https://blog.csdn.net/Luowaterbi/article/details/107688072 for details .
In addition to some of the main dependencies introduced by springboot, there are
mybatis-spring-boot-starter
Implement comments to manipulate MySQL database
mysql-connector-java
Connect MySQL and Java
pagehelper-spring-boot-starter
Pagination of front-end pages
shiro-spring
Front-end permission control
3. Code content
<?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.3.1.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>demo</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
</properties>
<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.1.3</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.17</version>
</dependency>
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
<version>1.2.10</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.github.theborakompanioni</groupId>
<artifactId>thymeleaf-extras-shiro</artifactId>
<version>2.0.0</version>
</dependency>
<dependency>
<groupId>org.apache.shiro</groupId>
<artifactId>shiro-spring</artifactId>
<version>1.4.1</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
二 、 application.yml
1. File location
2. Explanation
The function of application.yml is the same as application.properties, both of which are configuration items. I wrote xml at the beginning, but xml is too cumbersome, and properties will have a lot of repetitive code, and the yml file is a tree structure, the code is highly readable, and it is convenient to write, so yml is used now. Note that yml needs to add this file by yourself. The symbol is not at the beginning , don't worry, that's it after writing.
3. Code content
server:
port: 8080
#使用8080端口
spring:
datasource:
username: root #数据库用户名
password: 9 #数据库用户密码
url: jdbc:mysql://localhost:3306/shixun?characterEncoding=utf8&useSSL=false&serverTimezone=UTC&rewriteBatchedStatements=true&allowPublicKeyRetrieval=true #连接数据库,我用的database是“shixun”,自行替换成自己的
driver-class-name: com.mysql.cj.jdbc.Driver
thymeleaf:
cache: false
prefix: classpath:/templates/ #之后页面html文件的路径前缀
suffix: .html #路径后缀
encoding: UTF-8
mode: HTML5
servlet:
content-type: text/html
Pay attention to the indentation! ! ! Similar to python, indentation cannot be omitted or increased. Indentation is the only relationship that distinguishes the code hierarchy.
The database password cannot have leading 0! ! ! I have been pitted by this for a long time, and it will not read the leading 0.
In addition , the url and driver-class-name of MySQL8.0 and MySQL5.0 are different , please check it yourself .