课时22::PageHelper分页插件

.1)实现的步骤

  1.引入jar包

    <!--添加pageHelper分页-->
    <dependency>
    <groupId>com.github.pagehelper</groupId>
    <artifactId>pagehelper</artifactId>
    <version>5.1.0-beta</version>
    </dependency>

  2.配置到主文件

 <plugins>
        <!-- com.github.pagehelper为PageHelper类所在包名 -->
        <plugin interceptor="com.github.pagehelper.PageInterceptor">
            <!-- 使用下面的方式配置参数,后面会有所有的参数介绍 -->
            <property name="reasonable" value="true"/>
        </plugin>
    </plugins>

  3.如何实现插件

 //执行方法
        Page<Object> pages = PageHelper.startPage(2, 5);
        List<Student> student= iStudentDao.queryPageStudentOrderByNo();
       for (Student s:student){
           System.out.println(s);
       }
        System.out.println("总页码:"+pages.getPages());
        System.out.println("当前页码:"+pages.getPageNum());
        System.out.println("当前数据量:"+pages.getPageSize());
        System.out.println("总数据量:"+pages.getTotal());
  Page<Student> page = 
                PageHelper.startPage(1, 10).doSelectPage(()-> iStudentDao.queryPageStudentOrderByNo());
        List<Student> result = page.getResult();
        for (Student s:result){
           System.out.println(s);
       }

  4.如果想拿到更多的数据可以

PageInfo pageInfo=new PageInfo(把查出来的集合放入即可);列如可以拿到一个页码数组 

  5.详细使用可以参考https://github.com/pagehelper/Mybatis-PageHelper/blob/master/wikis/zh/HowToUse.md

原文地址:https://www.cnblogs.com/thisHBZ/p/12511359.html