• SSM框架中Mybatis的分页插件PageHelper分页失效的原因


    引用博客:个人博客地址:https://alexaccele.github.io/

    PageHelper是Mybatis的一个很好的分页插件,但要使用它的分页功能需要注意一下几点

    1.导入相关包,例如maven导入依赖

    1 <dependency>
    2     <groupId>com.github.pagehelper</groupId>
    3     <artifactId>pagehelper</artifactId>
    4     <version>5.1.4</version>
    5 </dependency>

    2.在mybatis-config.xml中添加插件

    引入 pageHelper插件

    注意这里要写成PageInterceptor, 5.0之前的版本都是写PageHelper, 5.0之后要换成PageInterceptor

    reasonable:分页合理化参数,默认值为false。
      当该参数设置为 true 时,pageNum<=0 时会查询第一页,
      pageNum>pages(超过总数时),会查询最后一页。
      默认false 时,直接根据参数进行查询。

    1 <plugins>
    2     <plugin interceptor="com.github.pagehelper.PageInterceptor">
    3         <!--分页参数合理化  -->
    4         <property name="reasonable" value="true"/>
    5     </plugin>
    6 </plugins>

    3.在Controller的方法中

    PageHelper.startPage(1,5);//从第一页开始,每页5条记录

    以上代码后面需紧跟查询语句

    1 List<Test> tests = testService.getAllTestsByTypeId(testTypeid);
    2 PageInfo pageInfo = new PageInfo(tests,5);

    当一个方法中有多个查询语句时,只有紧跟在PageHelper.starPage()方法后的查询结果才会分页。

    缺少以上三步都会导致分页失效

    参考:https://www.cnblogs.com/smfx1314/archive/2018/04/23/8920278.html

  • 相关阅读:
    java内置数据类型
    docker安装及配置
    redis持久化
    golang linux安装
    TCP/IP协议
    php高并发,大流量
    C语言阐述进程和线程的区别
    python 消息队列-rabbitMQ 和 redis介绍使用
    python 新手题目-文件读写-关键字判断
    python IO模式(多路复用和异步IO深入理解)
  • 原文地址:https://www.cnblogs.com/116970u/p/10371964.html
Copyright © 2020-2023  润新知