1.导入依赖
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper</artifactId>
<version>4.1.0</version>
</dependency>
2.在mybatis的主配置文件中添加:
<plugins>
<plugin interceptor="com.github.pagehelper.PageInterceptor">
</plugin>
</plugins>
3.编写代码
Page<Object> objects = com.github.pagehelper.PageHelper.startPage(1, 4);//第一页,4条记录
List<Account> accounts = mapper.selectByExample(null);//null表示无条件
PageInfo<Account> pageInfo=new PageInfo<>(accounts,3);//分页的详细信息,第一个参数为查询到的list,第二个参数为显示多少页,该对象可以获取当前是否为第一页,显示页数的集合