1.mybatis的分页插件PageHelper包
<dependency>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-core</artifactId>
<version>1.4.0</version>
</dependency>
2.在mybatis配置中添加
<plugins>
<plugin interceptor="com.github.pagehelper.PageInterceptor"></plugin>
</plugins>
3.开启分页
在查询功能之前使用PageHelper.startPage(int pageNum, int pageSize)
开启分页功能 。
PageHelper.startPage(int pageNum, int pageSize)
pageNum:当前页的页码
pageSize:每页显示的条数
4.把查询的结果封装到PageInfo类中。
PageInfo<User> pageInfo=new PageInfo<User>(list);