首页 > 代码库 > PageUtil

PageUtil

package util;

import java.util.List;

import entity.Street;

//分页工具类
public class PageUtil {
//页号
private int pageNo;
//每页条数 设置默认值
private int pageSize=5;
//总条数
private int totalCount;
//总页数
private int totalPage;
//上一页
private int pre;
//下一页
private int next;
//一页的数据
private List<Street> list;
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 getTotalCount() {
return totalCount;
}
//设置总条数
public void setTotalCount(int totalCount) {
this.totalCount = totalCount;
//设置好总条数,就可以决定总页数,页号是否正确,上一页,下一页都可以确定
//设置总页数 比如: totalCount:10 pageSize=3
//totalCount%pageSize=1 totalCount/pageSize=3 需要3+1页
setTotalPage(totalCount%pageSize==0?totalCount/pageSize:totalCount/pageSize+1);
//验证页号
if(pageNo<1){
pageNo=1;
}
if(pageNo>totalPage){
pageNo=totalPage;
}
//上一页,下一页
if(pageNo<=1){
pre=1;
}
else{
pre=pageNo-1;
}
if(pageNo>=totalPage){
next=totalPage;
}
else{
next=pageNo+1;
}

}
public int getTotalPage() {
return totalPage;
}
public void setTotalPage(int totalPage) {
this.totalPage = totalPage;
}
public int getPre() {
return pre;
}
public void setPre(int pre) {
this.pre = pre;
}
public int getNext() {
return next;
}
public void setNext(int next) {
this.next = next;
}
public List<Street> getList() {
return list;
}
public void setList(List<Street> list) {
this.list = list;
}




}

PageUtil