詳解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);//頁碼,每頁顯示數(shù)量 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);//頁碼,每頁顯示數(shù)量 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; }
到此這篇關(guān)于springboot-mysql-pagehelper分頁插件集成的文章就介紹到這了,更多相關(guān)springboot-mysql-pagehelper分頁插件內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
SpringBoot之@Value獲取application.properties配置無效的解決
這篇文章主要介紹了SpringBoot之@Value獲取application.properties配置無效的解決方案,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2023-03-03spring boot + mybatis如何實現(xiàn)數(shù)據(jù)庫的讀寫分離
這篇文章主要給大家介紹了關(guān)于spring boot + mybatis如何實現(xiàn)數(shù)據(jù)庫的讀寫分離的相關(guān)資料,文中通過示例代碼介紹的非常詳細,對大家學習或者使用spring boot具有一定的參考學習價值,需要的朋友們下面來一起學習學習吧2019-09-09Java技能點之SimpleDateFormat進行日期格式化問題
這篇文章主要介紹了Java技能點之SimpleDateFormat進行日期格式化問題,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2023-04-04