zoukankan      html  css  js  c++  java
  • 处理tk.mybatis 和 mybatisplus共存不能分页

    缘由:

      新搭建了一个springboot的单体架构,在融合原项目时,由于原项目使用tk.mybatis,新项目使用mybatisplus,所以导致,将老项目迁至新项目时,老项目中的分页失效。

    展示一下模块架构

     在infrastructure中使用分页:

        @Override
        //@Cacheable
        public Map<String, Object> queryAll(AnimalAdminTaskRecordQueryCriteria criteria, Pageable pageable) {
            getPage(pageable);
            PageInfo<AnimalAdminTaskRecord> page = new PageInfo<>(queryAll(criteria));
            Map<String, Object> map = new LinkedHashMap<>(2);
            map.put("content", generator.convert(page.getList(), AnimalAdminTaskRecordDto.class));
            map.put("totalElements", page.getTotal());
            return map;
        }
    
    
        @Override
        //@Cacheable
        public List<AnimalAdminTaskRecord> queryAll(AnimalAdminTaskRecordQueryCriteria criteria){
            return baseMapper.selectList(QueryHelpPlus.getPredicate(AnimalAdminTaskRecord.class, criteria));
        }
    

     在domain和application中使用(分页不生效

        public ResponseVO page(Page page, Map<String, Object> param) {
            PageHelper.startPage(page.getPage(), page.getLimit());
            List<UTag> uTagList = uTagMapper.selectBySelective(param);
            Page pages = new Page(page.getPage(), page.getLimit(), uTagMapper.countBySelective(param));
            pages.setItems(uTagList);
            return ResponseVO.success(pages);
        }
    

    添加分页配置

    import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
    import com.github.pagehelper.PageInterceptor;
    import org.springframework.context.annotation.Bean;
    import org.springframework.context.annotation.Configuration;
    
    import java.util.Properties;
    
    @Configuration
    public class MyBatisPlusConfig {
        /*
         * 分页插件,自动识别数据库类型
         * 多租户,请参考官网【插件扩展】
         */
        @Bean
        public PaginationInterceptor paginationInterceptor() {
            return new PaginationInterceptor();
        }
    
        /*处理tk.mybatis 和 mybatisplus共存不能分页的情况*/
        @Bean
        PageInterceptor pageInterceptor(){
            PageInterceptor pageInterceptor = new PageInterceptor();
            Properties properties = new Properties();
            properties.setProperty("helperDialect", "mysql");
            pageInterceptor.setProperties(properties);  // 由此可进入源码,
            return pageInterceptor;
        }
    } 

     重启项目,问题解决

    不要让未来的你,来埋怨如今的自己。
  • 相关阅读:
    [zoj3627]模拟吧
    [zoj3623]背包模型
    [hdu4358]树状数组
    [hdu1272]并查集
    [hdu3308]线段树
    [hdu5033]单调队列
    [hdu1506]单调队列(栈)
    [hdu2888]二维RMQ
    [hdu4123]dfs区间化+RMQ
    [hdu1242]优先队列
  • 原文地址:https://www.cnblogs.com/fuhui-study-footprint/p/14509813.html
Copyright © 2011-2022 走看看