https://pagehelper.github.io/docs/howtouse/
<!--分页插件-->
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper</artifactId>
<version>5.3.2</version>
</dependency>
@Configuration
public class AppConfig {
@Bean
public PageInterceptor pageInterceptor() {
PageInterceptor pageInterceptor = new PageInterceptor();
Properties properties = new Properties();
// 分页合理化,true开启,如果分页参数不合理会自动修正。默认false不启用
properties.setProperty("reasonable", "true");
pageInterceptor.setProperties(properties);
return pageInterceptor;
}
}
[Ref] 整合PageHelper实现分页
业务提供 查询所有学生的方法
// com.zhangziwa.practisesvr.mapper.UserMapper#listStudents
<select id="listStudents" resultMap="StudentMap">
SELECT * FROM students
</select>
// com.zhangziwa.practisesvr.mapper.UserMapper
List<Student> listStudents();
不使用分页插件 会查出全部
List<Student> students = userMapper.listStudents();
使用分页插件 会分页查询
PageHelper.startPage(1, 10, true);
PageHelper.orderBy("age asc");
List<Student> students = userMapper.listStudents();
PageInfo<Student> studentPageInfo = PageInfo.of(students);
[Q&A] 在系统中发现了多个分页插件