mybatisplus使用配置
时间: 2023-11-22 13:44:24 浏览: 39
Mybatis-plus 是 Mybatis 的增强工具,可以简化 Mybatis 的开发流程。使用 Mybatis-plus 需要进行以下配置:
1. 引入 Mybatis-plus 依赖:
```xml
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.4.2</version>
</dependency>
```
2. 配置数据源:
```yaml
spring:
datasource:
url: jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf-8&useSSL=false
username: root
password: root
driver-class-name: com.mysql.jdbc.Driver
```
3. 配置 Mybatis-plus:
```java
@Configuration
@MapperScan("com.example.demo.mapper")
public class MybatisPlusConfig {
@Bean
public PaginationInterceptor paginationInterceptor() {
return new PaginationInterceptor(); }
}
```
其中,`@MapperScan` 注解用于扫描 Mapper 接口,`PaginationInterceptor` 用于分页查询。
4. 编写 Mapper 接口和对应的 XML 文件。