ofbiz 分页代码

String pageNumber = request.getParameter("pageNumber");
String pageSize = request.getParameter("pageSize");
// 当前页
int intPage = Integer.parseInt((pageNumber == null || pageNumber.equals("0")) ? "1" : pageNumber);
// 每页显示条数
int number = Integer.parseInt((pageSize == null || pageSize.equals("0")) ? "2" : pageSize);
// 每页的开始记录 第一页为1 第二页为number +1
int lowIndex = (intPage - 1) * number;
EntityListIterator eli = null;
List<EntityCondition> connList = FastList.newInstance();


EntityFindOptions efo = new EntityFindOptions(true, EntityFindOptions.TYPE_SCROLL_SENSITIVE,
EntityFindOptions.CONCUR_READ_ONLY, false);
try {
TransactionUtil.begin();
eli = delegator.find("CenterTrade",
EntityCondition.makeCondition(UtilMisc.toMap("tradeSource", 4, "tradeType", 0, "auditing", 1)),
null, UtilMisc.toSet("recordId", "sponsorUserId", "tradeSource", "tradeResult"),
UtilMisc.toList("-createdStamp"), efo);
int totalPage = (eli.getResultsSizeAfterPartialList() + number - 1) / number;
List<GenericValue> pages = eli.getPartialList(lowIndex, number);
request.setAttribute("pageSize", number);
request.setAttribute("pageNumber", intPage);
request.setAttribute("pages", pages);
request.setAttribute("total", totalPage);
TransactionUtil.commit();
} catch (GenericEntityException e) {
// TODO Auto-generated catch block
e.printStackTrace();
try {
TransactionUtil.rollback();
} catch (GenericTransactionException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
} finally {
try {
if (eli != null) {
eli.close();
}
} catch (GenericEntityException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

你可能感兴趣的:(ofbiz 分页代码)