小编最近在经历后端框架的使用迁移,虽然不是页失小编来做,但是效及有个分页的情况让小编和一个同事去搞。说一下小编这边的完美需求:原来框架使用Mybatis-plus进行分页,要更换的替换新框架若依是使用Pagehelper。所以现在需求让我们把若依的若依干掉,使用Mybatis-plus,使用Mybatis-plus的页失生态还是挺好的,方便,效及最重要的完美是和原来的框架一样,不需要更改。替换存在问题:需要把若依以前的若依分页全部改成Mybatis-plus的分页,那我们就按个换喽,使用谁让咱们喜欢搬砖!页失 先说一下问题出现的原因:Mybatis和Mybatis-plus存在冲突,Pagehelper依赖于Mybatis,源码下载所以冲突了!! 解决方案:删Pagehelper和Mybatis的依赖,然后一点点的改若依一些基本配置的分页就好,最后在加上Mybatis-plus的分页插件配置!最最重要的是要扫描到写的分页插件,不然不生效! org.mybatis.spring.boot mybatis-spring-boot-starter ${ spring-boot.mybatis} com.github.pagehelper pagehelper-spring-boot-starter ${ pagehelper.boot.version} com.baomidou mybatis-plus-boot-starter ${ spring-boot.mybatis-plus} com.github.pagehelper pagehelper-spring-boot-starter 整个类全部注释! / * 分页工具类 * @author ruoyi */ / * 设置请求分页数据 */ protected void startPage(){ PageUtils.startPage(); } / * 清理分页的线程变量 */ protected void clearPage(){ PageUtils.clearPage(); } / * 响应请求分页数据 */ @SuppressWarnings({ "rawtypes", "unchecked" }) protected TableDataInfo getDataTable(List list){ TableDataInfo rspData = new TableDataInfo(); rspData.setCode(HttpStatus.SUCCESS); rspData.setRows(list); rspData.setMsg("查询成功"); rspData.setTotal(new PageInfo(list).getTotal()); return rspData; @Configuration public class MybatisPlusConfig { / * 新的分页插件,一缓和二缓遵循mybatis的规则,需要设置 MybatisConfiguration#useDeprecatedExecutor = false 避免缓存出现问题(该属性会在旧插件移除后一同移除) */ @Bean public MybatisPlusInterceptor mybatisPlusInterceptor() { MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor(); interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL)); return interceptor; } 我们发现在core中已经给了我们提示,他配置了一个,我们只需要把我们刚刚写的云服务器配置类加上去,就可以扫描到这配置,然后生效了!! 不配置不生效(切记切记)! 我们找到所在位置,添加上全路径即可,这里我们对若依的架构修改了名称,也就是若依的core包下的! 我们的宗旨是不影响之前的使用,需要我们新写一个分页,因为他们的export接口都使用了原来的分页,虽然分页没了,但是只要不调用还是不会报错的! 原来的方法: / * 获取参数配置列表 */ @RequiresPermissions("system:config:list") @GetMapping("/list") public TableDataInfo list(SysConfig config){ startPage(); List list = configService.selectConfigList(config); return getDataTable(list); 修改后的方法: 这里统一返回值我是使用我们以前架构的高防服务器,大家也可以使用若依自带的AjaxResult,只需要添加上Page即可,原来的方法我们不动,重新写一个两个参数的方法。 / * 获取参数配置列表 */ @RequiresPermissions("system:config:list") @GetMapping("/list") public R list(Page page, SysConfig config) { return R.ok(configService.selectConfigList(page, config)); / * 新分页 * @param page * @param config * @return */ @Override public Page selectConfigList(Page page, SysConfig config) { return configMapper.selectConfigList(page,config); / * 新分页 * @param page * @param config * @return */ 这样依次对ruoyi-modules-system项目进行修改,还有一些job和gen,不要和不用的就注释掉,只要不报错,原来的项目分页就可以展示出来,原来不改造之前是total和pages都是0,改造后恢复正常。 总的来说就是删依赖,加依赖,注释一些不要的,添加一个新的分页方法即可,都是搬砖的活,哈哈!! 这样之后我们发现system项目中的分页是有问题,是因为xml文件里没有指定对象.属性。于是把xml的一个例子修改了,现在分享给大家: where d.del_flag = 0 AND dept_id = #{ dept.deptId} AND parent_id = #{ dept.parentId} AND dept_name like concat(%, #{ dept.deptName}, %) AND status = #{ dept.status} ${ dept.params.dataScope} order by d.parent_id, d.order_num一、若依前言
二、删依赖
1、删除根目录的依赖
2、根目录添加依赖
3、ruoyi-common-core模块删除依赖
三、修改文件
1、注释PageUtils
2、注释BaseController分页方法
四、配置Mybatis-plus分页
1、在ruoyi-common-core中新建配置类
2、配置上可以扫描的
五、修改ruoyi-modules-system
1、SysConfigController改造
2、ISysConfigService新增分页方法
3、SysConfigServiceImpl新增分页实现方法
4、SysConfigMapper新增分页接口
5、总结
六、补充