import java.util.List;
public class PagingEntity {
/**
* 总页数
* dateCount=10 every=3
* 查询的总条数%每页显示的条数等不等于0?查询的总条数/每页显示的条数否则查询的总条数/每页显示的条数+1
* totalCount=dateCount%every==0?dateCount/every:(dateCount/every+1)
*/
private int dateCount;
/**
* 数据库查询的总条数
*/
private int total;
/**
* 每页显示的条
*/
private int every;
/**
* 当前页
*
*/
private int current;
/**
* 上一页
* previousPage=current==1?1:(current-1);
*/
private int previousPage;
/**
* 下一页
* 当前页小于总页数,当前页+1否则等于当前页
* nextPage=current<totalCount?current+1:current;
*/
private int nextPage;
/**
*开始索引= 当前页-1*每页显示的条数+1
* beginIndex=(current-1)*every+1
*
*结束索引= 每页显示的条数*当前页
* endIndex=every*current;
*/
private int beginIndex;
private int endIndex;
/**
* 用来存储EmpServiceImp类中query查询方法中返回的list集合
*/
private List rows;
public int getDateCount() {
return dateCount;
}
public void setDateCount(int dateCount) {
this.dateCount = dateCount;
}
public int getTotal() {
return total;
}
public void setTotal(int total) {
this.total = total;
}
public List getRows() {
return rows;
}
public void setRows(List rows) {
this.rows = rows;
}
public int getEvery() {
return every;
}
public void setEvery(int every) {
this.every = every;
}
public int getCurrent() {
return current;
}
public void setCurrent(int current) {
this.current = current;
}
public int getPreviousPage() {
return previousPage;
}
public void setPreviousPage(int previousPage) {
this.previousPage = previousPage;
}
public int getNextPage() {
return nextPage;
}
public void setNextPage(int nextPage) {
this.nextPage = nextPage;
}
public int getBeginIndex() {
return beginIndex;
}
public void setBeginIndex(int beginIndex) {
this.beginIndex = beginIndex;
}
public int getEndIndex() {
return endIndex;
}
public void setEndIndex(int endIndex) {
this.endIndex = endIndex;
}
}
实体类
调用类逻辑
public class ComputePag {
/**
*
* @param dateCount总页数
* @param current当前页
* @param every每页显示的条数
* 这三个都是传过来的值
*/
public static PagingEntity computeMethod(int current,int every,int dateCount){
PagingEntity pe =new PagingEntity();
//在把这三个值设入PagingEntity类中对应的set里
pe.setDateCount(dateCount);
pe.setCurrent(current);
pe.setEvery(every);
//总页数=(数据库查询的总数%每页显示的条数==0?数据库查询的总数/每页显示的条数:(数据库查询的总数/每页显示的条数+1))
int totalCount=(dateCount%every==0?dateCount/every:(dateCount/every+1));
//下一页=(当前页<总页数?当前页+1:当前页)
int nextPage=(current<totalCount?current+1:current);
//上一页=(当前页==1?当前页:当前页-1)
int previousPage=(current==1?current:current-1);
//开始索引= (当前页-1)*每页显示的条数+1
int beginIndex=(current-1)*every+1;
//结束索引= 当前页*每页显示的条数
int endIndex=current*every;
pe.setTotalCount(totalCount);
pe.setNextPage(nextPage);
pe.setPreviousPage(previousPage);
pe.setBeginIndex(beginIndex);
pe.setEndIndex(endIndex);
//返回PagingEntity pe实体类
return pe;
}
}