分页逻辑类


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;
	}
	

}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值