引入的mybatis-plus-boot-starter已经集成了MyBatis包下 一、如果单独升级所用的mybatis包 需要首先将其集成的mybatisb包依赖排除:exclude,然后引入单独的较高版本的MyBatis包依赖 二、
引入的mybatis-plus-boot-starter已经集成了MyBatis包下
一、如果单独升级所用的mybatis包
需要首先将其集成的mybatisb包依赖排除:exclude,然后引入单独的较高版本的MyBatis包依赖
二、mybatis 更换为 mybatis-plus
删除原有依赖
添加mybatis-plus的依赖
添加yml配置 基于SpringBoot || SpringCloud
#mybatis-plus配置控制台打印完整带参数sql语句mybatis-plus: mapperLocations: classpath:com/idc/mapper*.xml type-aliases-package: com.idc.entity configuration: map-underscore-to-camel-case: true call-setters-on-nulls: true log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
三、集成mybatis 转为集成 mybatis-plus
Maven导入
2、配置yml
#mybatis-plus
mybatis-plus:
mapperPackage: com.xn.mapper
typeAliasesPackage: com.xn.mapper
mapperLocations: classpath:mapper
@EnableTransactionManagement(proxyTargetClass = true)
@Configuration
@MapperScan("${mybatis-plus.mapperPackage}")
public class MybatisPlusConfig {
@Bean
public MybatisPlusInterceptor mybatisPlusInterceptor() {
MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
// 分页插件
interceptor.addInnerInterceptor(paginationInnerInterceptor());
// 乐观锁插件
interceptor.addInnerInterceptor(optimisticLockerInnerInterceptor());
return interceptor;
}
public PaginationInnerInterceptor paginationInnerInterceptor() {
PaginationInnerInterceptor paginationInnerInterceptor = new PaginationInnerInterceptor();
// 设置数据库类型为Mysql
paginationInnerInterceptor.setDbType(DbType.mysql);
// 设置最大单页限制数量,默认 500 条,-1 不受限制
paginationInnerInterceptor.setMaxLimit(-1L);
return paginationInnerInterceptor;
}
public OptimisticLockerInnerInterceptor optimisticLockerInnerInterceptor() {
return new OptimisticLockerInnerInterceptor();
}
@Bean
public MetaObjectHandler metaObjectHandler() {
return new CreateAndUpdateMetaObjectHandler();
}
@Bean
public MybatisPlusSqlInjector easySqlInjector () {
return new MybatisPlusSqlInjector();
}
}
四、
假如 当前模块的依赖,引用的依赖有Mybatis-plus的依赖,那么本module自动继承api-common的依赖,也会使用Mybatis-plus。
如果你使用了Mybatis-plus,那么你可以去掉Mybatis的依赖,将xml的寻址改为Mybatis-plus的方式。这样,你的项目模块中就既能使用Mybatis,也能使用Mybatis-plus。
只保留:
mybatis-plus:
mapper-locations: classpath:mappers/*xml
type-aliases-package: com.czf.common.entities
来源地址:https://blog.csdn.net/weixin_40024188/article/details/128162814
--结束END--
本文标题: MyBatis-plus使用时与MyBatis冲突?
本文链接: https://www.lsjlt.com/news/416663.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-05-03
2024-05-03
2024-05-03
2024-05-03
2024-05-03
2024-05-03
2024-05-03
2024-05-03
2024-05-03
2024-05-03
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0