1.首先需要在maven工程中引入pagehelper的依赖
<!-- pageHelper分页插件 -->
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper</artifactId>
<version>5.1.11</version>
</dependency>
2.需要在mybatis-config.xml中配置pagehelper-Interceptor 的plugins
<plugins>
<plugin interceptor="com.github.pagehelper.PageInterceptor"></plugin>
</plugins>
3.可以在业务逻辑中使用分页插件进行分页
@RequestMapping("/emps")
public String getStudents(@RequestParam(value="pn",defaultValue = "1") Integer pn,Model model) {
//设置分页为每页5条数据
PageHelper.startPage(pn, 5);
List<Student> allStudent = studentService.getAllStudent();
//将分页信息包装成pageInfo,并用model传递