public class Page {
private Integer currentPage;//当前页
private int pageSize;//每页显示记录条数
private int totalPage;//总页数
private List<?> dataList;//每页显示的数据
private int star;//开始数据
public Integer getCurrentPage() {
return currentPage;
}
public void setCurrentPage(Integer currentPage) {
this.currentPage = currentPage;
}
public int getPageSize() {
return pageSize;
}
public void setPageSize(int pageSize) {
this.pageSize = pageSize;
}
public int getTotalPage() {
return totalPage;
}
public void setTotalPage(int totalPage) {
this.totalPage = totalPage;
}
public List<?> getDataList() {
return dataList;
}
public void setDataList(List<?> dataList) {
this.dataList = dataList;
}
public int getStar() {
return star;
}
public void setStar(int star) {
this.star = star;
}
public Page pageConver(Integer pageNo, Integer pageSize, List list) {
//刚开始的页面为第一页
if (pageNo == null) {
this.setCurrentPage(1);
} else {
this.setCurrentPage(pageNo);
}
//设置每页数据
this.setPageSize(pageSize);
//每页的开始数
this.setStar((pageNo - 1) * this.getPageSize());
//list的大小
int count = list.size();
//设置总页数
this.setTotalPage(count % pageSize== 0 ? count / pageSize: count / pageSize+ 1);
//对list进行截取
this.setDataList(list.subList(this.getStar(), count - this.getStar() > this.getPageSize() ? this.getStar() + this.getPageSize() : count));
return this;
}
}
分页封装
最新推荐文章于 2024-06-25 14:51:49 发布