package cn.ksource.core.page;
|
|
import java.util.List;
|
|
/**
|
* 分页Bean
|
*/
|
public class PageBean {
|
|
// 指定的或是页面参数
|
private int page; // 当前页
|
private int pageSize; // 每页显示多少条
|
|
// 查询数据库
|
private int recordCount; // 总记录数
|
private List content; // 本页的数据列表
|
|
// 计算
|
private int totalPages; // 总页数
|
private int beginPageIndex; // 页码列表的开始索引(包含)
|
private int endPageIndex; // 页码列表的结束索引(包含)
|
|
public PageBean() {}
|
|
/**
|
* 只接受前4个必要的属性,会自动的计算出其他3个属生的值
|
*
|
* @param page
|
* @param pageSize
|
* @param recordCount
|
* @param content
|
*/
|
public PageBean(int page, int pageSize, int recordCount, List content) {
|
this.page = page;
|
this.pageSize = pageSize;
|
this.recordCount = recordCount;
|
this.content = content;
|
|
// 计算总页码
|
totalPages = (recordCount + pageSize - 1) / pageSize;
|
|
// 计算 beginPageIndex 和 endPageIndex
|
// >> 总页数不多于10页,则全部显示
|
if (totalPages <= 10) {
|
beginPageIndex = 1;
|
endPageIndex = totalPages;
|
}
|
// >> 总页数多于10页,则显示当前页附近的共10个页码
|
else {
|
// 当前页附近的共10个页码(前4个 + 当前页 + 后5个)
|
beginPageIndex = page - 4;
|
endPageIndex = page + 5;
|
// 当前面的页码不足4个时,则显示前10个页码
|
if (beginPageIndex < 1) {
|
beginPageIndex = 1;
|
endPageIndex = 10;
|
}
|
// 当后面的页码不足5个时,则显示后10个页码
|
if (endPageIndex > totalPages) {
|
endPageIndex = totalPages;
|
beginPageIndex = totalPages - 10 + 1;
|
}
|
}
|
}
|
|
public List getContent() {
|
return content;
|
}
|
|
public void setContent(List content) {
|
this.content = content;
|
}
|
|
public int getPage() {
|
return page;
|
}
|
|
public void setPage(int page) {
|
this.page = page;
|
}
|
|
public int getTotalPages() {
|
return totalPages;
|
}
|
|
public void setTotalPages(int totalPages) {
|
this.totalPages = totalPages;
|
}
|
|
public int getPageSize() {
|
return pageSize;
|
}
|
|
public void setPageSize(int pageSize) {
|
this.pageSize = pageSize;
|
}
|
|
public int getRecordCount() {
|
return recordCount;
|
}
|
|
public void setRecordCount(int recordCount) {
|
this.recordCount = recordCount;
|
}
|
|
public int getBeginPageIndex() {
|
return beginPageIndex;
|
}
|
|
public void setBeginPageIndex(int beginPageIndex) {
|
this.beginPageIndex = beginPageIndex;
|
}
|
|
public int getEndPageIndex() {
|
return endPageIndex;
|
}
|
|
public void setEndPageIndex(int endPageIndex) {
|
this.endPageIndex = endPageIndex;
|
}
|
|
}
|