1、首先创建一个空的SpringBoot项目
2、导入以下依赖
org.springframework.boot spring-boot-starterorg.springframework.boot spring-boot-starter-testtest org.springframework spring-web5.3.16 org.springframework.data spring-data-commonsorg.mybatis mybatis-spring2.0.7 mysql mysql-connector-javaruntime org.mybatis.spring.boot mybatis-spring-boot-starter2.2.2 com.alibaba druid-spring-boot-starter1.2.8 org.springframework.boot spring-boot-starter-web
3、选择连接数据库
4、选择要生成代码的表,生成代码
5、给配置文件添加配置
# Spring配置
spring:
datasource:
driverClassName: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://localhost:3306/数据库名字?useSSL=false&characterEncoding=utf-8&useUnicode=true&serverTimezone=Asia/Shanghai
username: root
password: 12345678
server:
port: 8080
# MyBatis配置
mybatis:
# 搜索指定包别名
# typeAliasesPackage: com.xxx.entity
# 配置mapper的扫描,找到所有的mapper.xml映射文件
mapperLocations: classpath:mapper/*.xml
# 加载全局的配置文件
# configLocation: classpath:mybatis/mybatis-config.xml
6、在Application文件里添加以下注解
@MapperScan("com.xxx.dao")
7、启动项目
8、随便点击一个接口测试,就成功了!



