更新时间:2021-10-21 10:23:13 来源:极悦 浏览933次
Java开发工具有很多, Java分页工具类只是其中之一。
import java.util.List;
/**
* Paging tool
* @author Administrator
*
*/
public class PageBean<T> {
private int pageNo = 1; //Current page
private int pageSize = 4; //Number of pages per page
private int totalCount; //Total number of records
private int totalPages; //Total pages--read only
private List<T> pageList; //The collection generic type corresponding to each page
public int getPageNo() {
return pageNo;
}
//The current page number cannot be less than 1 and cannot be greater than the total number of pages
public void setPageNo(int pageNo) {
if(pageNo<1)
this.pageNo = 1;
else if(pageNo > totalPages)
this.pageNo = totalPages;
else
this.pageNo = pageNo;
}
public int getPageSize() {
return pageSize;
}
public void setPageSize(int pageSize) {
this.pageSize = pageSize;
}
//The total number of records determines the total number of pages
public void setTotalCount(int totalCount) {
this.totalCount = totalCount;
this.totalPages = (this.totalCount%this.pageSize==0)?this.totalCount/this.pageSize:this.totalCount/this.pageSize+1;
}
public int getTotalCount() {
return totalCount;
}
//Read only
public int getTotalPages() {
return totalPages;
}
public List<T> getPageList() {
return pageList;
}
public void setPageList(List<T> pageList) {
this.pageList = pageList;
}
public PageBean(int pageNo, int pageSize, int totalCount, int totalPages,
List<T> pageList) {
super();
this.pageNo = pageNo;
this.pageSize = pageSize;
this.totalCount = totalCount;
this.totalPages = totalPages;
this.pageList = pageList;
}
public PageBean() {
super();
// TODO Auto-generated constructor stub
}
}
mysql 分页:select * from table limit (pageNo-1)*pageSize,pageSize;
oracle分页:select a.* (select table.*,rowum rn from table) a where rn>(pageNo-1)*pageSize and rn <=pageNo*pageSize;
这是最简单的分页工具之一。
0基础 0学费 15天面授
Java就业班有基础 直达就业
业余时间 高薪转行
Java在职加薪班工作1~3年,加薪神器
工作3~5年,晋升架构
提交申请后,顾问老师会电话与您沟通安排学习