1.新建一个Project
2.选择一个Spring Initializr
3.Artifact就是项目名
4.选择需要的依赖 (SpringWeb、MyBatis框架、MySQL的驱动)
5.选择项目所在的目录,一定要和项目同名
6.Finish之后就完成了一半的项目搭建
7.在项目的/src/main/resources下新建一个application.properties来填写Mybatis的配置信息
8.在项目的/src/main/resources下新建mubatis-config.xml
9.配置Maven仓库
10.在File->Settings->Build,Execution,Deployment->Build Tools->Maven中配置好Maven
11.导入Maven依赖
12./src/main/resources/templates中存放html页面
13.新建controller包,创建一个controller类来跳转到index.html
14.添加@controller注解,给方法添加@RequestMapping注解
15.添加数据库
16.application.yml就等于application.properties
17.添加Mybatis映射文件的配置
18.补全Mapper和Service
19.遇到问题1:Initialization failed for 'https://start.spring.io'
解决方法:
20.遇到问题2:
解决方法:(在pom.xml中添加Thymeleaf的配置)
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<!--thymeleaf模板-->
<dependency>
<groupId>org.thymeleaf</groupId>
<artifactId>thymeleaf-spring5</artifactId>
</dependency>
<dependency>
<groupId>org.thymeleaf.extras</groupId>
<artifactId>thymeleaf-extras-java8time</artifactId>
</dependency>
补充:前端thymeleaf 头文件 xmlns:th="http://www.thymeleaf.org"