序言
/** * pageInfo对象中属性含义 * private int pageNum;//当前页码 * private int pageSize;//设置每页多少条数据 * private int size;//当前页有多少条数据 * private int startRow;//当前页码第一条数据的 * private int endRow;//当前页码的开始条 * private int pages;//当前页码结束条 * private int prePage;//上一页(页面链接使用) * private int nextPage;//下一页(页面链接使用) * private boolean isFirstPage;//是否为第一页 * private boolean isLastPage;//是否为最后一页 * private boolean hasPreviousPage;//是否有前一页 * private boolean hasNextPage;//是否有下一页 * private int navigatePages;//导航页码数(就是总共有多少页) * private int[] navigatePageNums;//导航页码数(就是总共有多少页),可以用来遍历 * private int navigateFirstPage;//首页号 * private int navigateLastPage;//尾页号 */ @Test void test() { int pageNum = 1; int pageSize = 3; //1.引入分页插件,pageNum是第几页,pageSize是每页显示多少条,默认查询总数count Page<ApArticle> page = PageHelper.startPage(pageNum, pageSize); //2.紧跟的查询就是一个分页查询-必须紧跟,这样才能保证安全分页, PageHelper 在 finally 代码段中自动清除了 ThreadLocal 存储的对象 List<ApArticle> articleList = apArticleService.list(); //3.使用PageInfo包装查询后的结果,3是连续显示的条数 PageInfo pageInfo = new PageInfo(articleList ,pageSize); System.out.println("总记录数:" + pageInfo.getTotal()); System.out.println("总页数:" + pageInfo.getPages()); System.out.println("一页的大小:" + pageInfo.getSize()); System.out.println("是否有前一页:" + pageInfo.isHasPreviousPage()); }
资料
- MyBatis-Plus MybatisPlus Pagehelper MyBatis Javamybatis-plus mybatisplus pagehelper mybatis mybatis-plus mybatisplus mybatis java sqlsessionfactory mybatis-plus pagehelper exception 插件mybatis mybatis-plus pagehelper mybatis-plus mybatis spring java mybatis-plus mybatis java plus mybatis-plus随笔mybatis java mybatisplus pagehelper插件 pagehelper插件mybatis pagehelper mybatis