该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
import java.util.List;
//封装页面:数据List,分页控件的数据:当前页码,一页显示的条数
public class Pager {
// 当前页码
private int pageNo;
// 一页显示的条数
private int pageSize;
// 总的页面,计算出来
private int totalPages;
// 总的记录数
private int totalRows;
// 数据List
private List rows;
public Pager(int pageNo, int pageSize, int totalRows) {
this.pageNo = pageNo;
this.pageSize = pageSize;
this.totalRows = totalRows;
// 错误处理
if (this.pageNo < 1) {
this.pageNo = 1;
}
if (this.pageSize < 1) {
this.pageSize = 10;
}
// 总的页面,计算出来
// if (this.totalRows % this.pageSize == 0) {
// this.totalPages = this.totalRows / this.pageSize;
// } else {
// this.totalPages = this.totalRows / this.pageSize + 1;
// }
// 分页算法
// 110 10 11 =(110+10-1)/10
// 101 10 11=(101+10-1)/10
// 109 10 11=(109+10-1)/10
this.totalPages = (this.totalRows + this.pageSize - 1) / this.pageSize;
// 处理当前页码不能超过总的页数
if (this.pageNo > this.totalPages) {
this.pageNo = this.totalPages;
}
}
public int getPageNo() {
return pageNo;
}
public void setPageNo(int pageNo) {
this.pageNo = pageNo;
}
public int getPageSize() {
return pageSize;
}
public void setPageSize(int pageSize) {
this.pageSize = pageSize;
}
public int getTotalPages() {
return totalPages;
}
public void setTotalPages(int totalPages) {
this.totalPages = totalPages;
}
public int getTotalRows() {
return totalRows;
}
public void setTotalRows(int totalRows) {
this.totalRows = totalRows;
}
public List getRows() {
return rows;
}
public void setRows(List rows) {
this.rows = rows;
}
@Override
public String toString() {
return "Pager [pageNo=" + pageNo + ", pageSize=" + pageSize + ", totalPages=" + totalPages + ", totalRows="
+ totalRows + ", rows=" + rows.size() + "]";
}
}