很多时候我们写DAO层接口会写一个查询所有记录的方法,但是在数据量非常大的时候,查询所有记录会巨慢无比,这时我们就需要用到分页查询。pagehelper就是个很好的分页插件。
1,配置
pagehelper的项目地址:https://github.com/pagehelper/pagehelper-spring-boot
我们只需在Maven中加入如下依赖即可:
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
<version>1.3.1</version>
</dependency>
2,执行分页查询
首先这里先写好DAO和Mapper XML的查询全部部分:
Mapper XML的<select>节点:
<select id="getAll" resultMap="userResultMap">
select * from `user`
</select>
DAO:
/**
* 获取全部用户
*/
List<User> getAll();
User类表示一个用户的POJO类。
然后