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

    本博客文章绝大多数为原创,少量为转载,代码经过测试验证,如果有疑问直接留言或者私信我。
    创作文章不容易,转载文章必须注明文章出处;如果这篇文章对您有帮助,点击右侧打赏,支持一下吧。
  • 相关阅读:
    es6 数组的扩展
    面向对象的7大原则及其实例
    flex 布局
    一、创建vue
    箭头函数
    destructuring
    spreed&rest
    变量新声明之let、const
    jQuery之遍历索引相关方法
    jQuery之位置坐标图形相关方法
  • 原文地址:https://www.cnblogs.com/passedbylove/p/14536479.html
Copyright © 2011-2022 走看看