一.创建项目
添加application.yml配置文件
添加启动类
在resources中添加mappers文件夹
在java中添加entity.,dao,service,controller包
二.在pom.xml中添加依赖
<!--MyBatisPlus依赖-->
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.5.1</version>
</dependency>
<!--LomBok依赖-->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId> <optional>true</optional>
</dependency>
<!--mysql依赖-->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
三.在application.yml中配置数据源
spring:
datasource:
type: com.zaxxer.hikari.HikariDataSource
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://localhost:3306/practice?characterEncoding=utf-8&useSSL=false&allowPublicKeyRetrieval=true
username: root
四.在启动类Demo.java中扫描dao