package com.ht.util;
public class BasePage{
public static final Integer DEFAULT_CURRENT=1; //默认显示第一页
public static final Integer DEFAULT_PAGE_NUM=10;//默认显示10条记录
protected Integer pageFirRecord=0; //当前页第一条记录
protected Integer currentPage=1; //当前页数
protected Integer totalPages; //总页数
protected Integer totalRecord; //总记录数
protected Integer showRecordNum=DEFAULT_PAGE_NUM; //每页显示记录数
protected Integer showPageNum; //当前页显示的记录数量
protected Integer prePage=1;
protected Integer nexePage=1;
public BasePage(){
}
public BasePage(Integer currentPage,Integer totalRecord){
this.setTotalRecord(totalRecord);
this.setTotalPages();
this.setCurrentPage(currentPage);
this.setShowPageNum();
this.setPageFirRecord();
this.setPrePage();
this.setNexePage();
}
/**
* 重载
* @param currentPage
* @param totalRecord
* @param showRecordNum
*/
public BasePage(Integer currentPage,Integer totalRecord,int showRecordNum){
this.setTotalRecord(totalRecord);
this.setShowRecordNum(showRecordNum);
this.setTotalPages();
this.setCurrentPage(currentPage);
this.setShowPageNum();
this.setPageFirRecord();
this.setPrePage(); //计算前一页页码
this.setNexePage(); //计算下一页页码
}
public Integer getPrePage() {
return prePage;
}
public void setPrePage() {
this.prePage = currentPage-1;
}
public Integer getNexePage() {
return nexePage;
}
public void setNexePage() {
if(currentPage==totalPages){ //如果当前页码为总页码,即最后一页
this.nexePage = 0; //返回0
}else{
this.nexePage = currentPage+1;
}
if(totalPages==0){ //如果总页数为0,怎么返回0;
this.nexePage = 0;
}
}
public Integer getShowPageNum() {
return showPageNum;
}
public void setShowPageNum() { //当前页显示的记录数量
if(currentPage*showRecordNum-totalRecord>0){
this.showPageNum = totalRecord-(currentPage-1)*showRecordNum;
}else{
this.showPageNum=showRecordNum;
}
}
public Integer getShowRecordNum() {
return showRecordNum;
}
public void setShowRecordNum(Integer showRecordNum) {
if(showRecordNum==0){ //如果记录数为0,则默认为5
this.showRecordNum=5;
}else{
this.showRecordNum = showRecordNum;
}
}
public Integer getTotalPages() {
return totalPages;
}
public void setTotalPages() { //计算总页数
if(totalRecord%showRecordNum==0){
this.totalPages = totalRecord/showRecordNum;
}else{
this.totalPages = totalRecord/showRecordNum+1;
}
}
public Integer getTotalRecord() {
return totalRecord;
}
public void setTotalRecord(Integer totalRecord) {
this.totalRecord = totalRecord;
}
public Integer getCurrentPage() {
return currentPage;
}
public void setCurrentPage(Integer currentPage) {
if(currentPage==0||currentPage<0){
currentPage=1;
}
if(currentPage>totalPages&&totalPages!=0){ //2010年8月27日增加,
this.currentPage=totalPages; //当前页大于总页数时为总页数,并且保证不存在记录时不出错,即totalPages!=0
}else if(totalPages==0){
this.currentPage=1;
}else{
this.currentPage = currentPage;
}
}
public void setPageFirRecord() { //第一条记录所在集合的标号,比实际排数少一
this.pageFirRecord = (getCurrentPage()-1)*showRecordNum;
}
public Integer getPageFirRecord() {
return pageFirRecord;
}
}
评论4
最新资源