tkmapper和mybatisplus 共存 如何配置配置文件
时间: 2023-05-23 18:01:47 浏览: 275
可以通过以下方式将 tkmapper 和 mybatisplus 配置在同一个配置文件中:
1. 导入 tkmapper 和 mybatisplus 依赖包。
2. 配置 mybatisplus 的数据源和 mapper 扫描路径,例如:
```properties
# mybatisplus 数据库配置
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf8&serverTimezone=Asia/Shanghai
spring.datasource.username=root
spring.datasource.password=root
# mybatisplus mapper 扫描路径
mybatis-plus.mapper-locations=classpath*:mapper/**/*.xml
```
3. 配置 tkmapper 的 mapper 扫描路径,例如:
```properties
# tkmapper mapper 扫描路径
tk.mybatis.mapper.mapper-locations=classpath:mapper/*.xml
```
4. 在 Mybatis 配置类中,分别配置 mybatisplus 和 tkmapper 的插件和拦截器,例如:
```java
@Configuration
public class MybatisConfig {
@Bean
public PaginationInterceptor paginationInterceptor() {
return new PaginationInterceptor();
}
@Bean
public MapperInterceptor mapperInterceptor() {
return new MapperInterceptor();
}
@Bean
public ConfigurationCustomizer configurationCustomizer() {
return new ConfigurationCustomizer() {
@Override
public void customize(Configuration configuration) {
configuration.setUseGeneratedKeys(true);
configuration.setCacheEnabled(false);
}
};
}
@Bean
public MapperScannerConfigurer mapperScannerConfigurer() {
MapperScannerConfigurer configurer = new MapperScannerConfigurer();
configurer.setBasePackage("com.example.demo.mapper");
return configurer;
}
}
```
以上是基本的配置方式,具体的细节还需要根据实际情况进行调整。
阅读全文
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![xml](https://img-home.csdnimg.cn/images/20250102104920.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![docx](https://img-home.csdnimg.cn/images/20241231044901.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![txt](https://img-home.csdnimg.cn/images/20241231045021.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![-](https://img-home.csdnimg.cn/images/20241231044901.png)
![-](https://img-home.csdnimg.cn/images/20241231044901.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)