Reference webpage
https://blog.csdn.net/gnail_oug/article/details/80229542
Integration steps
Pom
<!-- pagehelper --> <dependency> <groupId>com.github.pagehelper</groupId> <artifactId>pagehelper-spring-boot-starter</artifactId> <version>1.2.5</version> </dependency>
application.properties configuration file
########################################## Page helper paging plug-in configuration pagehelper.helperDialect=oracle pagehelper.reasonable=true pagehelper.supportMethodsArguments=true pagehelper.params=count=countSql
Controller
@Autowired private UserService userService; @RequestMapping(value = "/getUsers", method = RequestMethod.GET) @ApiOperation(value = "query", notes = "Paging query user", produces = "application/json") public PageInfo<User> getUsers(@RequestParam(value = "jsonString") String jsonString, HttpServletRequest request) throws Exception{ //Finishing parameters 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; }
Service
@Autowired private UserMapper userMapper; public Page<User> getUsers(UserQuery query){ Page<User> userList = userMapper.getUsers(query); return userList; }
Mapper
Page<User> getUsers(UserQuery query);
_Several Explanations
Types of databases supported in the application.properties configuration file
At present, Pagehelper plug-in supports six kinds of database paging, Oracle,Mysql,MariaDB,SQLite,Hsqldb,PostgreSQL. Different databases only need to modify helper Dialect.
Oracle Database Writing
########################################## Page helper paging plug-in configuration pagehelper.helperDialect=oracle pagehelper.reasonable=true pagehelper.supportMethodsArguments=true pagehelper.params=count=countSql
MySQL Database Writing
########################################## Page helper paging plug-in configuration pagehelper.helperDialect=mysql pagehelper.reasonable=true pagehelper.supportMethodsArguments=true pagehelper.params=count=countSql
SQL Server Database Writing
########################################## Page helper paging plug-in configuration pagehelper.helperDialect=sqlserver pagehelper.reasonable=true pagehelper.supportMethodsArguments=true pagehelper.params=count=countSql
Page class description
Page is a class in the com.github.pagehelper package, which is a subclass of java.util.ArrayList.
Note that the paging code PageHelper.startPage(pageNo,pageSize); only valid for the next first query.