java分页封装到dao层,DAO分页函数

/**

* 本类封装分页和排序查询请求参数.

* 本类参考自springside的ORM封装设计

*

*

*

*/

public class QueryParameter {

public static final String ASC = "asc";

public static final String DESC = "desc";

protected int pageNo = 1;

protected int pageSize = -1;

protected String orderBy = null;

protected String order = ASC;

protected boolean autoCount = false;

/**

* 获得每页的记录数量,无默认值.

*/

public int getPageSize() {

return pageSize;

}

public void setPageSize(int pageSize) {

this.pageSize = pageSize;

}

/**

* 是否已设置每页的记录数量.

*/

public boolean isPageSizeSetted() {

return pageSize > -1;

}

/**

* 获得当前页的页号,序号从1开始,默认为1.

*/

public int getPageNo() {

return pageNo;

}

public void setPageNo(int pageNo) {

this.pageNo = pageNo;

}

/**

* 根据pageNo和pageSize计算当前页第一条记录在总结果集中的位置,序号从0开始.

*/

public int getFirst() {

if (pageNo < 1 || pageSize < 1)

return -1;

else

return ((pageNo - 1) * pageSize);

}

/**

* 是否已设置第一条记录记录在总结果集中的位置.

*/

public boolean isFirstSetted() {

return (pageNo > 0 && pageSize > 0);

}

/**

* 获得排序字段,无默认值.

*/

public String getOrderBy() {

return orderBy;

}

public void setOrderBy(String orderBy) {

this.orderBy = orderBy;

}

/**

* 是否已设置排序字段.

*/

public boolean isOrderBySetted() {

return StringUtils.isNotBlank(orderBy);

}

/**

* 获得排序方向,默认为asc.

*/

public String getOrder() {

return order;

}

/**

* 设置排序方式向.

*

* @param order

* 可选值为desc或asc.

*/

public void setOrder(String order) {

if (ASC.equalsIgnoreCase(order) || DESC.equalsIgnoreCase(order)) {

this.order = order.toLowerCase();

} else

throw new IllegalArgumentException(

"order should be 'desc' or 'asc'");

}

/**

* 是否自动获取总页数,默认为false. 注意本属性仅于query by Criteria时有效,query by HQL时本属性无效.

*/

public boolean isAutoCount() {

return autoCount;

}

public void setAutoCount(boolean autoCount) {

this.autoCount = autoCount;

}

}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值