<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
<version>1.2.3</version>
</dependency>
在maven项目中,首先添加依赖,然后在service层中,调用
public interface IRealAuthService {
PageInfo queryPage(RealAuthQueryObject qo);
}
在实现类中编写方法
public class RealAuthServiceImpl implements IRealAuthService{
@Override
public PageInfo queryPage(RealAuthQueryObject qo) {
PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize());
List result = realAuthMapper.queryForList(qo);
return new PageInfo(result);
}
}
qo为:
public class QueryObject {
private int currentPage=1;
private int pageSize=5;
}
public class RealAuthQueryObject extends QueryObject {
}
controller控制器:
public class RealAuthController {
@Autowired
private IRealAuthService realAuthService;
@RequestMapping("/realAuth")
public String realAuthPage(@ModelAttribute("qo") RealAuthQueryObject qo, Model model){
PageInfo pageResult=realAuthService.queryPage(qo);
model.addAttribute("pageResult",pageResult);
return "/realAuth/list";
}
}
PageHelper中默认PageInfo的成员变量
//当前页
private int pageNum;
//每页的数量
private int pageSize;
//当前页的数量
private int size;
//由于startRow和endRow不常用,这里说个具体的用法
//可以在页面中"显示startRow到endRow 共size条数据"
//当前页面第一个元素在数据库中的行号
private int startRow;
//当前页面最后一个元素在数据库中的行号
private int endRow;
//总记录数
private long total;
//总页数
private int pages;
//结果集
private List<T> list;
//第一页
private int firstPage;
//前一页
private int prePage;
//是否为第一页
private boolean isFirstPage = false;
//是否为最后一页
private boolean isLastPage = false;
//是否有前一页
private boolean hasPreviousPage = false;
//是否有下一页
private boolean hasNextPage = false;
//导航页码数
private int navigatePages;
//所有导航页号
private int[] navigatepageNums;