package com.qxueyou.scc.base.model;
|
|
public class Pager {
|
|
/*
|
* ÿҳÏÔʾÌõÊý
|
*/
|
private int pageSize;
|
|
/*
|
* µ±Ç°Ò³Âë
|
*/
|
private int pageNum;
|
|
/*
|
* ¼Ç¼×ÜÊý
|
*/
|
private int totalCount;
|
|
public Pager(){
|
//constructor
|
}
|
|
public Pager(int pageSize,int pageNum){
|
this.pageSize=pageSize;
|
this.pageNum=pageNum;
|
}
|
|
public int getPageSize() {
|
return pageSize <= 0?Integer.MAX_VALUE:pageSize;
|
}
|
|
public void setPageSize(int pageSize) {
|
this.pageSize = pageSize;
|
}
|
|
public int getPageNum() {
|
return pageNum <= 0?1:pageNum;
|
}
|
|
public int getOffset() {
|
return pageNum <= 1?0:(pageNum-1)*this.getPageSize();
|
}
|
|
public void setPageNum(int pageNum) {
|
this.pageNum = pageNum;
|
}
|
|
public int getTotalCount() {
|
return totalCount;
|
}
|
|
public void setTotalCount(int totalCount) {
|
this.totalCount = totalCount;
|
}
|
|
/**
|
* ¼ÆËã×ÜÒ³Êý
|
* @return
|
*/
|
public int getPageCount(){
|
return totalCount%pageSize>0?totalCount/pageSize+1:totalCount/pageSize;
|
}
|
|
/**
|
* ¼ÆËã·ÖÒ³À¸Æðʼҳ
|
* @return
|
*/
|
public int getPageDispayStart(){
|
|
int startGap = Math.min(pageNum-1,2);
|
int endGap = Math.min(getPageCount()-pageNum,2);
|
|
if(startGap<=endGap){
|
return Math.max(pageNum-startGap,1);
|
}else{
|
return Math.max(pageNum-(4-endGap),1);
|
}
|
|
}
|
|
/**
|
* ¼ÆËã·ÖÒ³À¸½áÊøÒ³
|
* @return
|
*/
|
public int getPageDispayEnd(){
|
int startGap = Math.min(pageNum-1,2);
|
int endGap = Math.min(getPageCount()-pageNum,2);
|
|
if(startGap<=endGap){
|
return Math.min(pageNum+(4-startGap),getPageCount());
|
}else{
|
return Math.min(pageNum+endGap,getPageCount());
|
}
|
}
|
}
|