目录
- 1 步骤
1 步骤
1 导入分页插件的依赖
代码语言:javascript复制<!--分页插件-->
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper</artifactId>
<version>5.0.0</version>
</dependency>
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-autoconfigure</artifactId>
<version>1.2.3</version>
</dependency>
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
<version>1.2.3</version>
</dependency>
<!--分页插件-->
2 yml里面进行配置
代码语言:javascript复制#分页插件
pagehelper:
helper-dialect: mysql
reasonable: true
support-methods-arguments: true
params: count=countSql
3 在controller层中使用(也可以在service层中):
代码语言:javascript复制@RequestMapping("/agentList")
public ModelAndView agentList(HttpServletRequest request, Integer pageNum, Integer
pageSize) throws Exception {
ModelAndView mv = new ModelAndView("myAgent");
User user = (User) request.getSession().getAttribute("user");
if(pageNum == null){
pageNum = 1;
}
if(pageSize == null){
pageSize = 6;
}
//使用分页插件
PageHelper.startPage(pageNum , pageSize);
List<Map> list = agentService.agentList(user.getId()); //获取后台数据列表(根据自己系统修改)
//根据查询的数据列表,得到分页的结果对象
PageInfo<Map> pageList = new PageInfo<Map>(list);
List<Map> datas = pageList.getList();
mv.addObject("datas", datas);
return mv;
}