mybatis升级为mybatis-plus实现方案

1.背景

老项目是mybatis的,但是新项目想使用mybatis-plus,

故需要升级

2.实现步骤

2.1、删除所有的mybatis包,一定要去除所有的mybatis包。包括其他依赖内的依赖

2.2、导入mybatis-plus包

<dependency>
    <groupId>com.baomidou</groupId>
    <artifactId>mybatis-plus-boot-starter</artifactId>
    <version>3.5.1</version>
</dependency>

2.3、修改配置

复制代码
# mybatis配置
#mybatis.mapperLocations=classpath:mapper/*.xml
#mybatis.configuration.map-underscore-to-camel-case=true
#mybatis.configuration.call-setters-on-nulls=true
#pagehelper.helperDialect=oracle
# mybatis-plus配置
mybatis-plus.mapper-locations=classpath:mapper/*.xml
mybatis-plus.global-config.db-config.db-type=oracle
mybatis-plus.global-config.db-config.field-strategy=not_empty
mybatis-plus.configuration.map-underscore-to-camel-case=true
复制代码

2.4、或者手动注入mybatis配置(重要)

复制代码
@Configuration
@MapperScan(basePackages = {"com.XXX.mapper"})
@EnableTransactionManagement
public class MybatisPlusConfig {
    /**
     * 性能分析拦截器,不建议生产使用
     */
//    @Bean
//    public PerformanceInterceptor performanceInterceptor(){
//        return new PerformanceInterceptor();
//    }
 
    /**
     * 分页插件
     */
    @Bean
    public PaginationInterceptor paginationInterceptor() {
        return new PaginationInterceptor();
    }
 
    /**
     * pagehelper的分页插件
     */
    @Bean
    public PageInterceptor pageInterceptor() {
        return new PageInterceptor();
    }
 
    @Bean
    public SqlSessionFactory sqlSessionFactory(DataSource dataSource) throws Exception {
        String mapperLocations = "classpath:mapper/*.xml";
        VFS.addImplClass(SpringBootVFS.class);
        final MybatisSqlSessionFactoryBean sessionFactory = new MybatisSqlSessionFactoryBean();
        sessionFactory.setDataSource(dataSource);
        sessionFactory.setMapperLocations(new PathMatchingResourcePatternResolver().getResources(mapperLocations));
        return sessionFactory.getObject();
    }
}
复制代码

 

posted @   浅笑19  阅读(720)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 【杭电多校比赛记录】2025“钉耙编程”中国大学生算法设计春季联赛(1)
历史上的今天:
2021-05-10 JavaScript 获取checkbox的值
点击右上角即可分享
微信分享提示