第一步:引入相关依赖
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper</artifactId>
<version>5.0.0</version>
</dependency>
第二步:在mybatis配置文件中引入插件
<plugins>
<plugin interceptor="com.github.pagehelper.PageInterceptor">
<!-- config params as the following -->
</plugin>
</plugins>
第三步:在controller层调用PageHelper类,并进行查询,然后包装返回
@RequestMapping("/emps")
public String getEmps(Model model,@RequestParam(value="pn",defaultValue = "1") Integer pn){
PageHelper.startPage(pn,5);
List emps = employeeService.getAll();
PageInfo pageInfo = new PageInfo(emps);
model.addAttribute("pageInfo",pageInfo);
return "list";
}