1.下载分页插件:https://github.com/pagehelper/Mybatis-PageHelper/blob/master/README_zh.md
2.配置分页插件
<plugins> <plugin interceptor="com.github.pagehelper.PageInterceptor"></plugin> </plugins>
3.使用分页插件
在查询之前设置分页
Page<Object> page = PageHelper.startPage(1, 5);
查询数据之后添加
PageInfo<Customer> pageInfo = new PageInfo<>(customers, 5);
属性介绍
System.out.println("当前页:" + pageInfo.getPageNum()); System.out.println("每页显示记录数:" + pageInfo.getPageSize()); System.out.println("总页数:" + pageInfo.getPages()); System.out.println("总记录数:" + pageInfo.getTotal()); System.out.println("是否有上一页:" + pageInfo.isHasPreviousPage()); System.out.println("是否有下一页:" + pageInfo.isHasNextPage()); System.out.println("导航页面:" + Arrays.toString(pageInfo.getNavigatepageNums()));