java的分页条件类

最近做项目,要实现分页,把以前写的分页类翻了出来,代码如下:


/**
 * @author yxd
 * 分页条件的抽象类
 */
public abstract class PageCondition {
	protected Integer pageSize;  //每页显示的记录数量
	protected Integer totalRecord;  //总记录数
	protected Integer currentPage;  //当前页
	protected Integer totalPage;    //总页数	
	
	public Integer getCurrentPage() {
		if(currentPage==null){
			return 1;
		}
		return Math.min(currentPage, getTotalPage());
	}
	public void setCurrentPage(Integer currentPage) {
		this.currentPage = currentPage;
	}	
	public Integer getPageSize() {
		return pageSize != null ? pageSize : 10;
	}
	public void setPageSize(Integer pageSize) {
		this.pageSize = pageSize;
	}
	public Integer getTotalRecord() {
		return totalRecord!=null? totalRecord:0;
	}
	public void setTotalRecord(Integer totalRecord) {
		this.totalRecord = totalRecord;
	}
	public Integer getTotalPage() {
		return (totalRecord+this.getPageSize()-1)/this.getPageSize();
	}
	public void setTotalPage(Integer totalPage) {
		this.totalPage = totalPage;
	}
	
	/**
	 * 根据当前页和每页的记录数计算开始的记录
	 * @return
	 */
	public static int getStartRecord(int currentPage,int pageSize){
		if(currentPage<1){
			currentPage=1;
		}
		return (currentPage-1)*pageSize;
	}	
	
	
	
	
	/**
	 * 数据的查询条件,可以是sql片段,或者其他约定的查询对象等等,由子类实现
	 * @return
	 * @throws Exception
	 */
	public abstract Object getCondition() throws Exception;
	
	
	
}


实现类

public class DepositCondition extends PageCondition{
	private Log log = LogFactory.getLog(DepositCondition.class);
	private String userInfo;//筛选条件(name或id)
	private String userVal;//筛选条件的值
	private int cityId=-1;  //城市
	private int money=-1;//保障金金额
	private int state=-1;//保障金状态
	private String timeNm;//保障金的操作时间类型(冻结时间或申退、违规时间)
	private String beginTime;//开始时间
	private String endTime;//结束时间
	private UserDepositQuery query;
	
	@Override
	public Object getCondition() throws Exception {
		//保证对于同样的查询条件,只生成一次,比如对总页数的查询和数据的查询
		if(this.query!=null){
			return this.query;
		}
		this.query=new UserDepositQuery();		
		//处理各种条件,生成查询类
		return this.query;
	}
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值