详解springboot-mysql-pagehelper分页插件集成
作者:王家五哥
这篇文章主要介绍了springboot-mysql-pagehelper分页插件集成,本文通过实例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下
pagehelper分页插件
springboot-mysql-pagehelper集成
pagehelperjar:
<dependency> <groupId>com.github.pagehelper</groupId> <artifactId>pagehelper-spring-boot-starter</artifactId> <version>0.1.0</version> </dependency>
application.properties配置:
#pagehelper,方言 pagehelper.helperDialect=mysql pagehelper.reasonable=true pagehelper.supportMethodsArguments=true pagehelper.pageSizeZero=true pagehelper.params=count=countSql
分页插件使用:(紧跟查询即可完成分页)
/** * http://127.0.0.1:8097/hello1?a=1&b=50 * @param request * @return * @throws SQLException */ @RequestMapping(value = "/hello1", method = RequestMethod.GET) @ResponseBody public PageInfo<String> index1(HttpServletRequest request,@RequestParam("a") int pageNum, @RequestParam("b") int pageSize) throws SQLException { if (StringUtils.isEmpty(pageNum)) { pageNum=0; pageSize=10; } PageHelper.startPage(pageNum, pageSize);//页码,每页显示数量 List<String> stringlist = (List<String>) iBaseService.findList("usermapper.selectuserlist",null); PageInfo<String> pageInfo = new PageInfo<String>(stringlist); return pageInfo; }
使用方式二:
@RequestMapping(value = "/hello11", method = RequestMethod.GET) @ResponseBody public Map<String, Object> index11(HttpServletRequest request,@RequestParam("a") int pageNum, @RequestParam("b") int pageSize) throws SQLException { if (StringUtils.isEmpty(pageNum)) { pageNum=0; pageSize=10; } PageHelper.startPage(pageNum, pageSize);//页码,每页显示数量 List<String> stringlist = (List<String>) iBaseService.findList("usermapper.selectuserlist",null); PageInfo<String> pageInfo = new PageInfo<String>(stringlist); Map<String, Object>datamap=new HashMap<String, Object>(); datamap.put("pagenum", pageInfo.getPageNum()); datamap.put("pagesize", pageInfo.getPageSize()); datamap.put("dataSize", pageInfo.getTotal()); datamap.put("datalist", pageInfo.getList()); return datamap; }
到此这篇关于springboot-mysql-pagehelper分页插件集成的文章就介绍到这了,更多相关springboot-mysql-pagehelper分页插件内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!