1.加依賴包java
<!--分頁攔截器--> <dependency> <groupId>com.github.pagehelper</groupId> <artifactId>pagehelper-spring-boot-starter</artifactId> <version>1.2.5</version> </dependency>
2.配置application.ymlmysql
pagehelper: helperDialect: mysql reasonable: true supportMethodsArguments: true params: count=countSql rowBoundsWithCount: true offset-as-page-num: true
3.編寫AdminController類git
@RequestMapping(value = "/getAdminListMap/{account}") public List<Map<String, Object>> getAdminListMap(@PathVariable("account") String account) { /** * 第一個參數:第幾頁 * 第二個參數:每頁獲取的條數 */ PageHelper.startPage(1,2); List<Map<String, Object>> adminListMap = adminService.getAdminListMap(account); PageInfo<Map<String, Object>> pageInfo = new PageInfo<>(adminListMap); System.out.println("總記錄數:" + pageInfo.getTotal()); System.out.println("總記頁數:" + pageInfo.getPages()); System.out.println("返回的記錄數:" + adminListMap.size()); return adminListMap; }
4.測試github