- 添加依赖
Maven:
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.2.0</version>
</dependency>
Gradle:
compile group: 'com.baomidou', name: 'mybatis-plus-boot-starter', version: '3.3.1.tmp'
2.配置
2.1.配置数据源
2.1.1.导入驱动
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.18</version>
</dependency>
2.1.2.配置数据源
spring:
datasource:
username: root
password: root
url: jdbc:mysql://XXX:3306/XXX
driver-class-name: com.mysql.jdbc.Driver
2.2.配置 MapperScan 注解
@SpringBootApplication
@MapperScan("com.baomidou.mybatisplus.samples.quickstart.mapper")
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
2.3.配置 sql 映射文件
在配置文件中:
mybatis-plus:
mapper-locations: classpath:/mapper/**/*.xml
参考官网:https://mp.baomidou.com/guide/
@TableId修饰的主键,想调整为自增主键:
mybatis-plus:
mapper-locations: classpath:/mapper/**/*.xml
global-config:
db-config:
id-type: auto
等分库分表了在改