网站制作经典案例,国内设计公司前十名,建设工程施工许可证在哪个网站办,建设网站的方案SpringBoot之整合PageHelper分页插件 文章目录 SpringBoot之整合PageHelper分页插件1. 引入坐标2. application.yml配置3. 基本使用4. 对多个查询执行分页1. 默认第一个Select语句会执行分页2. 让Pagehelper也能执行多个分页的方法3. 完整案例 详细配置请查看官网或MyBatis分页…SpringBoot之整合PageHelper分页插件 文章目录 SpringBoot之整合PageHelper分页插件1. 引入坐标2. application.yml配置3. 基本使用4. 对多个查询执行分页1. 默认第一个Select语句会执行分页2. 让Pagehelper也能执行多个分页的方法3. 完整案例 详细配置请查看官网或MyBatis分页插件之PageHelper详细介绍-CSDN博客 1. 引入坐标
!--pagehelper--dependencygroupIdcom.github.pagehelper/groupIdartifactIdpagehelper-spring-boot-starter/artifactIdversion1.3.0/version!--排除pagehelper的依赖mybatis和mybatis-spring的jar包以免与mybatis-plus的冲突导致报NoClassFound org.mybatis.logging.LoggerFactory--exclusionsexclusiongroupIdorg.mybatis/groupIdartifactIdmybatis/artifactId/exclusionexclusiongroupIdorg.mybatis/groupIdartifactIdmybatis-spring/artifactId/exclusion/exclusions/dependency2. application.yml配置
pagehelper:helper-dialect: mysqlreasonable: truesupport-methods-arguments: trueparams: countcountSql3. 基本使用 Autowiredprivate PublicService publicService; GetMapping(value /getUserList)public ResultPageInfo getUserList(RequestParam(namepageNo, defaultValue1) Integer pageNo,RequestParam(namepageSize, defaultValue5) Integer pageSize){StringBuffer sql new StringBuffer();sql.append(SELECT\n a.id,\n a.username,\n b.id AS file_id,\n b.file_url,\n b.file_size,\n FROM\n sys_user a\n LEFT JOIN sys_file b ON a.id b.parent_id \n WHERE\n a.del_flag 0);Result result new Result();Map map new HashMap(5);map.put(sql,sql.toString());//获取第pageNo页pageSize条内容默认查询总数countPageHelper.startPage(pageNo, pageSize);//紧跟着的第一个select方法会被分页ListMapString, Object mapList publicService.sqlQuery(map);result.setResult(mapList);result.setSuccess(true);PageInfo pageInfo new PageInfo(mapList);return Result.OK(pageInfo);4. 对多个查询执行分页 Pagehelper中只有紧跟在 PageHelper.startPage 方法后的第一个 Mybatis 的查询Select方法会被分页。 1. 默认第一个Select语句会执行分页 案例代码如下 Autowired
private PublicService publicService;public ListSignatureUser getUserList(){//获取第pageNo页pageSize条内容默认查询总数countPageHelper.startPage(pageNo, pageSize);//紧跟着的第一个select方法会被分页ListMapString, Object mapList publicService.sqlQuery(map);IPage iPage IPageUtil.pageData(mapList);//下面这个查询不会分页ListSignatureUser signatureUserList publicService.getSignatureUserList(map);System.out.println(signatureUserList.size());return signatureUserList;
}2. 让Pagehelper也能执行多个分页的方法 在查询参数中设置pageNum与pageSize参数使其第二个查询也能分页如下 Autowired
private PublicService publicService; public ListSignatureUser getUserList(){//获取第pageNo页pageSize条内容默认查询总数countPageHelper.startPage(pageNo, pageSize);//紧跟着的第一个select方法会被分页ListMapString, Object mapList publicService.sqlQuery(map);IPage iPage IPageUtil.pageData(mapList);System.out.println(第一个查询分页结果,iPage);Map map1 new HashMap(3);//加入mybatis分页的参数pageNum与pageSize则其他查询也能分页map1.put(pageNum, pageNo);map1.put(pageSize, pageSize);ListSignatureUser signatureUserList publicService.getSignatureUserList(map1);System.out.println(signatureUserList.size());return signatureUserList;
}3. 完整案例 Autowiredprivate PublicService publicService; ApiOperation(value 用户信息列表, notes 用户信息列表)GetMapping(value /getUserList)public Result? getUserList(RequestParam(namepageNo, defaultValue1) Integer pageNo,RequestParam(namepageSize, defaultValue5) Integer pageSize){StringBuffer sql new StringBuffer();sql.append(SELECT\n a.id,\n a.username,\n b.id AS file_id,\n b.file_url,\n b.file_size,\n FROM\n sys_user a\n LEFT JOIN sys_file b ON a.id b.parent_id \n WHERE\n a.del_flag 0);//一.直接sql方式分页Map map new HashMap(5);map.put(sql,sql.toString());//获取第pageNo页pageSize条内容默认查询总数countPageHelper.startPage(pageNo, pageSize);//紧跟着的第一个select方法会被分页ListMapString, Object mapList publicService.sqlQuery(map);IPage iPage IPageUtil.pageData(mapList);//return Result.OK(iPage);//二.对象集合分页Map map1 new HashMap(3);map1.put(pageNum, pageNo);map1.put(pageSize, pageSize);ListSignatureUser signatureUserList publicService.getSignatureUserList(map1);System.out.println(signatureUserList.size());return Result.OK(IPageUtil.pageData(signatureUserList));}