一、引入相关依赖
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.1.0</version>
</dependency>
二、编写配置文件
spring:
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://localhost:3306/test?serverTimezone=GMT%2B8&characterEncoding=UTF-8&allowMultiQueries=true
username: root
password: root
mybatis-plus:
mapper-locations: classpath:mappers/*.xml
可能需要自己编写sql语句,因此需要配置mapper-locations去找到相应的xml文件
三、编写实体类
四、编写mapper
- 多项目下,可以在配置类上使用@MapperScan包扫描多包路径
- 不使用@MapperScan,就必须使用@Mapper并且类路径在Springboot路径下能找到,才可以正常使用。