• mybatis升级为mybatis-plus实现方案


    1.背景

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

    故需要升级

    2.实现步骤

    步骤一:删除mybatis相关的依赖包

    步骤二:导入mybatis-plus相关的包

    com.baomidou mybatis-plus-boot-starter 3.0-RELEASE

    步骤三:修改application.properties文件

    其他配置不变

    # 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

    步骤四:手动配置数据库对象(非充重要)

    @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();
        }
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38

    3.系统化学系mybatis-plus

    mybatis-plus详细的图文教程 - 博客园

    4.完美!

  • 相关阅读:
    Java桥接模式
    每天一个设计模式之单例模式(六种写法)
    centos-7-安装minio-20220620
    Kafka:容器安装篇
    使用docker部署mysql8.0+zabbix5.0
    C++程序加速方法
    module.exports和exports
    从 Java 8 升级到 Java 17 全过程,避坑!
    学习二十大奋进新征程线上知识答题活动回顾
    java计算机毕业设计网上书店进销存管理系统源程序+mysql+系统+lw文档+远程调试
  • 原文地址:https://blog.csdn.net/m0_54850467/article/details/126464952