zoukankan      html  css  js  c++  java
  • pageHelper从tkmybatis移植到mybatis-plus出现getTotal getPageNum getPageSize都返回0的问题

    之前使用tkmybatis时候的分页代码

        final Integer pageNum = parameter.getPageNum();
            final Integer pageSize = parameter.getPageSize();
    
            final Map<String, Object> map = objectToMap(parameter);
    
            PageHelper.startPage(Optional.ofNullable(pageNum).orElse(1), Optional.ofNullable(pageSize).orElse(15));
    
            Page<TenantDTO> page = baseMapper.queryPage(map);

    返回结果

    {
      "list":[...] ,
        "total": 1,
        "pageSize": 15,
        "pageNum": 1
    }

    之前的maven依赖 

          <dependency>
                <groupId>com.github.pagehelper</groupId>
                <artifactId>pagehelper-spring-boot-starter</artifactId>
                <version>1.3.0</version>
                <exclusions>
                    <exclusion>
                        <artifactId>mybatis</artifactId>
                        <groupId>org.mybatis</groupId>
                    </exclusion>
                </exclusions>
            </dependency>

    解决方法

    mybatis-plus中的依赖

            <dependency>
                <groupId>com.github.pagehelper</groupId>
                <artifactId>pagehelper</artifactId>
                <version>5.2.0</version>
            </dependency>
            <dependency>

    新增Configuration配置

    import com.baomidou.mybatisplus.autoconfigure.ConfigurationCustomizer;
    
    @Configuration
    @EnableTransactionManagement
    @MapperScan("com.h2.*.*.mapper*")
    public class MybatisPlusConfiguration {
    
    
      /***
         * 兼容PageHelper分页插件,防止出现page.getPageNum,page.getTotal,page.getSize都返回0
         * https://blog.csdn.net/u012280292/article/details/99678037
         * @return
         */
        @Bean
        ConfigurationCustomizer mybatisConfigurationCustomizer() {
            return configuration -> configuration.addInterceptor(new PageInterceptor());
        }
    
    }

    解决方法转载自:https://blog.csdn.net/u012280292/article/details/99678037

    本博客文章绝大多数为原创,少量为转载,代码经过测试验证,如果有疑问直接留言或者私信我。
    创作文章不容易,转载文章必须注明文章出处;如果这篇文章对您有帮助,点击右侧打赏,支持一下吧。
  • 相关阅读:
    ubuntu部分端口命令的使用----开启端口/开启防火墙
    ElasticSearch 5.0及head插件安装
    维基百科语料中的词语相似度探索
    Mac下多版本JDK安装
    Mac OS 终端利器 iTerm2
    android mat 转 bitmap
    simHash 简介以及 java 实现
    Python数据可视化之matplotlib实践 源码 第二篇 精进 第六章
    Python数据可视化之matplotlib实践 源码 第二篇 精进 第五章
    Python数据可视化之matplotlib实践 源码 第一篇 入门 第四章
  • 原文地址:https://www.cnblogs.com/passedbylove/p/14536479.html
Copyright © 2011-2022 走看看