02 |
您所在的位置:网站首页 › pagehelper依赖冲突 › 02 |
工欲善其事,必先利其器,Ruoyi已经提供了许多系统实用的功能了,但在数据访问层上使用的Mybatis+pagehelper的组合,也是非常好用的,但所有操作都需要写sql完成,对于一些简单的数据库操作来说每次都写sql其实也挺麻烦的,为了更简化以后的代码开发,我们将mybatis-plus整合进来,并且保留pagehelper的分页功能,以最小的修改获得mybatis-plus的能力。 引用官方的原话,MyBatis-Plus是一个 MyBatis 的增强工具,在 MyBatis 的基础上只做增强不做改变,为简化开发、提高效率而生。在后面的开发过程中我们将看到她的魅力,下面开始整合mybatis-plus,主要有添加引用、解决冲突、修改配置、修改代码生成器模板几个步骤。 1、引入mybatis-plus 找到源码根目录下的pom.xml,添加mybatis-plus:
com.baomidou mybatis-plus-boot-starter 3.5.3
此处以mybatis-plus中的版本为主,因此移除pagehelper-spring-boot-starter中引入的mybatis,打开根目录下的pom.xml,找到pagehelper-spring-boot-starter做如下修改: com.github.pagehelper pagehelper-spring-boot-starter ${pagehelper.boot.version}
org.mybatis mybatis
3、打开ruoyi-comm项目下的pom.xml,添加mybatis-plus依赖; 4、打开ruiyi-framework项目,找到config目录,打开MyBatisConfig.java,移除@Configuration注解;新建MybatisPlusConfig.java,添加mybatis-plus配置,内容如下: @Configuration publicclassMybatisPlusConfig{ @Bean publicMybatisPlusInterceptormybatisPlusInterceptor() { MybatisPlusInterceptorinterceptor=newMybatisPlusInterceptor(); PaginationInnerInterceptorpaginationInnerInterceptor=newPaginationInnerInterceptor(DbType.MYSQL); paginationInnerInterceptor.setMaxLimit(10000L); paginationInnerInterceptor.setOverflow(true); paginationInnerInterceptor.setOptimizeJoin(true); interceptor.addInnerInterceptor(paginationInnerInterceptor); returninterceptor; } } 5、打开ruoyi-admin项目中application.yml配置文件,删除mybatis配置,添加mybatis-plus配置,如下: #mybatis: # # 搜索指定包别名 # typeAliasesPackage: com.ruoyi.**.domain # # 配置mapper的扫描,找到所有的mapper.xml映射文件 # mapperLocations: classpath*:mapper/**/*Mapper.xml # # 加载全局的配置文件 # configLocation: classpath:mybatis/mybatis-config.xml mybatis-plus: configuration: cache-enabled: false default-fetch-size: 20 jdbc-type-for-null: null map-underscore-to-camel-case: true global-config: banner: false db-config: id-type: auto table-underline: true insert-strategy: mapper-locations: classpath*:mapper/**/*Mapper.xml type-aliases-package: com.ruoyi.**.domain 6、修改代码生成器使用mybatis-plus的功能,打开domain.java.vm文件,添加 @TableName @TableFIeld注解,如下图: 至此,mybatis-plus整合完成,下一篇开始介绍加油站管理系统的主要功能和开发细节。 |
CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3 |