http://www.javashuo.com/article/p-vkcinkyz-gt.htmljava
<!-- pagehelper --> <dependency> <groupId>com.github.pagehelper</groupId> <artifactId>pagehelper-spring-boot-starter</artifactId> <version>1.2.5</version> </dependency>
########################################## pagehelper分頁插件配置 pagehelper.helperDialect=oracle pagehelper.reasonable=true pagehelper.supportMethodsArguments=true pagehelper.params=count=countSql
@Autowired private UserService userService; @RequestMapping(value = "/getUsers", method = RequestMethod.GET) @ApiOperation(value = "查詢", notes = "分頁查詢用戶", produces = "application/json") public PageInfo<User> getUsers(@RequestParam(value = "jsonString") String jsonString, HttpServletRequest request) throws Exception{ //整理參數 UserQuery query = null; try { query = JsonUtil.parseJson(jsonString, UserQuery.class); } catch (Exception e) { return null; } Integer pageNo = query.getPageNo() == null?1:query.getPageNo(); Integer pageSize = query.getPageSize() == null?10:query.getPageSize(); PageHelper.startPage(pageNo,pageSize); PageInfo<User> pageInfo = new PageInfo<>(userService.getUsers(query)); return pageInfo; }
@Autowired private UserMapper userMapper; public Page<User> getUsers(UserQuery query){ Page<User> userList = userMapper.getUsers(query); return userList; }
Page<User> getUsers(UserQuery query);
目前Pagehelper插件支持Oracle,Mysql,MariaDB,SQLite,Hsqldb,PostgreSQL六種數據庫分頁,不一樣數據庫只須要修改helperDialect就行。mysql
########################################## pagehelper分頁插件配置 pagehelper.helperDialect=oracle pagehelper.reasonable=true pagehelper.supportMethodsArguments=true pagehelper.params=count=countSql
########################################## pagehelper分頁插件配置 pagehelper.helperDialect=mysql pagehelper.reasonable=true pagehelper.supportMethodsArguments=true pagehelper.params=count=countSql
########################################## pagehelper分頁插件配置 pagehelper.helperDialect=sqlserver pagehelper.reasonable=true pagehelper.supportMethodsArguments=true pagehelper.params=count=countSql
Page是com.github.pagehelper包裏的類,它是java.util.ArrayList的子類。git
須要注意的是,分頁代碼PageHelper.startPage(pageNo,pageSize);只對其後的第一個查詢有效。github