<!-- 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就行。
########################################## 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的子类。
需要注意的是,分页代码PageHelper.startPage(pageNo,pageSize);只对其后的第一个查询有效。
热门工具 换一换