今天写了个分页的帮助类。
package com.tit.edu.util;
public class PageHelp {
private int pageSize = 10;
private int scount;
private int ecount;
private int sumPage;
private int sumCount;
private int prePage = 1;
public PageHelp(int sumCount) {
super();
this.sumCount = sumCount;
this.setScount();//设置开始显示记录数的位置
this.setEcount();//设置结束显示记录数的位置
this.setSumPage();//设置总页数
}
public PageHelp(int sumCount,int pageSize) {
super();
this.pageSize = pageSize;
this.sumCount = sumCount;
this.setScount();//设置开始显示记录数的位置
this.setEcount();//设置结束显示记录数的位置
this.setSumPage();//设置总页数
}
public int getPageSize() {
return pageSize;
}
public void setPageSize(int pageSize) {
this.pageSize = pageSize;
}
public int getNextpage(){
if(prePage +1 > sumPage){
prePage = sumPage;
}else{
prePage = prePage + 1;
}
this.setEcount();
this.setScount();
return prePage;
}
public int getFrontpage(){
if(prePage - 1 <0){
prePage = 1;
}else{
prePage = prePage - 1;
}
this.setEcount();
this.setScount();
return prePage;
}
public void setSumPage(){
sumPage = (int) Math.ceil((double) sumCount / pageSize);
}
public int getSumpage() {
return sumPage;
}
public void setPagesize(int pageSize) {
this.pageSize = pageSize;
}
public int getScount() {
return scount;
}
public void setScount() {
scount = pageSize*(prePage-1);
}
public int getEcount() {
return ecount;
}
public void setEcount() {
ecount = prePage*pageSize;
}
public int getPrepage() {
return prePage;
}
public void setPrepage(int prePage) {
this.prePage = prePage;
this.setScount();//设置开始显示记录数的位置
this.setEcount();//设置结束显示记录数的位置
}
public int getSumCount() {
return sumCount;
}
public void setSumCount(int sumCount) {
this.sumCount = sumCount;
}
}