baseMapper要用的话要配置啥
时间: 2023-07-11 11:26:47 浏览: 46
如果你想在使用 MyBatis-Plus 的 BaseMapper 接口时,需要进行以下配置:
1. 在 pom.xml 文件中引入 MyBatis-Plus 的依赖:
```xml
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>最新版本</version>
</dependency>
```
2. 在 application.yml 或 application.properties 文件中配置 MyBatis-Plus:
```yaml
mybatis-plus:
mapper-locations: classpath*:mapper/**/*.xml # mapper.xml 文件所在路径,可以使用通配符
```
3. 在项目中定义 Entity 类,并继承 MyBatis-Plus 的 BaseMapper 接口:
```java
public interface UserMapper extends BaseMapper<User> {
//...
}
```
4. 在 Spring Boot 启动类中添加 @MapperScan 注解,扫描 Mapper 接口所在的包:
```java
@SpringBootApplication
@MapperScan("com.example.demo.mapper") // Mapper 接口所在的包
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}
```
完成以上配置后,就可以在项目中使用 MyBatis-Plus 的 BaseMapper 接口了。