1.通过Spring Initializr搭建springboot项目
2.项目名称改成你喜欢的
3.自动导入一些需要用到得jar
点击next,点击finish,创建成功
4.引入thymeleat启动器,将以下代码放入pom.xml中
<!--添加thymeleat启动器-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
5.这时候启动项目会报错,是因为你没有配置mybatis
打开application.properties文件,在里面配置你的mysql
spring.datasource.url=jdbc:mysql://129.28.48.43:3306/mysql?serverTimezone=CTT&useUnicode=true&characterEncoding=utf-8&allowMultiQueries=true
spring.datasource.username=root
spring.datasource.password=guan9038
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
6.创建以下文件
7.sqlMapConfig.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration></configuration>
8.在application.properties文件中添加
mybatis.config-location=classpath:mybatis/sqlMapConfig.xml
mybatis.mapper-locations=classpath:mybatis/mapper/*.xml
9.之后你就可以正常写controller,service,dao层啦
注:需要代码请发邮箱