1. 引入pom依赖
<!--mybatis-plus-->
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.4.1</version>
</dependency>
<!--数据库依赖-->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<!--单元测试依赖-->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>
2. 修改配置文件
application.properties:
# 服务端口
server.port=8001
# mysql数据库连接
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/mybatisdemo?serverTimezone=GMT%2B8
spring.datasource.username=root
spring.datasource.password=123456
application.yml:
# 服务端口
server:
port: 8001
# mysql数据库连接
spring:
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://localhost:3306/mybatisdemo?serverTimezone=GMT%2B8
username: root
password: 123456
3. 配置自动生成代码
3.1 引入pom依赖
<!--mybatis-plus自动代码生成插件-->
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-generator</artifactId>
<version>3.4.1</version>
</dependency>
<!-- velocity 模板引擎, Mybatis Plus 代码生成器需要 -->
<dependency>
<groupId>org.apache.velocity</groupId>
<artifactId>velocity-engine-core</artifactId>
<version>2.3</version>
</dependency>
<!-- freemarker 模板引擎, Mybatis Plus 代码生成器需要 -->
<dependency>
<groupId>org.freemarker</groupId>
<artifactId>freemarke