// 分页
private int pageSize = 4;
private int totalPage;
private int curPage;
private int totalRows;
//Action 执行方法
public String execute() throws Exception {
superInit();
String sDate = startDate;
String eDate = endDate;
if (StringUtil.isNotEmpty(sDate)) {
sDate += " 00:00:00";
}
if (StringUtil.isNotEmpty(eDate)) {
eDate += " 23:59:59";
}
tradeStatusMap = WebConsts.getTradeStatusMap();
tradeTypeMap = WebConsts.getTradeTypeMap();
totalRows = alipayClient.queryOrdersCount(userM.getVUserAccount(),
orderNum, tradeType, tradeStatus, sDate, eDate); //获取记录总数
PaginationUtil pUtil = new PaginationUtil(totalRows, pageSize);//分页工具
totalPage = pUtil.getTotalPage();
if (curPage <= 0) {
curPage = 1;
}
if (curPage > totalPage) {
curPage = totalPage;
}
orderList = alipayClient.queryOrders(userM.getVUserAccount(), orderNum,
tradeType, tradeStatus, sDate, eDate,
pUtil.getStartRow(curPage), pUtil.getEndRow(curPage));
return SUCCESS;
}
================================================================================================
分页工具类
public class PaginationUtil {
private int totalRow;
private int pageSize;
/**
*
* @param totalRow
* 记录总数量
* @param pageSize
* 每页记录数量
*/
public PaginationUtil(int totalRow, int pageSize) throws Exception {
if (totalRow < 0) {
throw new Exception("分页总记录数量不能小于0");
}
if (pageSize <= 0) {
throw new Exception("每页记录数量不能小于等于0");
}
this.totalRow = totalRow;
this.pageSize = pageSize;
}
/**
* 获取某一页的起始行号
*
* @param page
* 页编号(从1开始)
* @return 当前页的起始行号
*/
public int getStartRow(int page) throws Exception {
int startRow = 0;
if (page <= 0) {
page = 1;
}
startRow = pageSize * (page - 1);
return startRow;
}
/**
* 获取某一页的结束行号
*
* @param page
* 页编号(从1开始)
* @return 当前页的结束行号
*/
public int getEndRow(int page) throws Exception {
int endRow = 0;
if (page <= 0) {
page = 1;
}
endRow = pageSize * page - 1;
if (endRow >= totalRow) {
endRow = totalRow - 1;
}
if (endRow < 0) {
endRow = 0;
}
return endRow;
}
/**
* 获取总页数
*
* @return
*/
public int getTotalPage() {
int pageCount = 0;
pageCount = totalRow / pageSize;
if (totalRow % pageSize > 0) {
pageCount++;
}
return pageCount;
}
}
======================================================================================================================
<@s.if test="totalPage>0">
<@s.iterator var="item" begin="1" end="totalPage">
<@s.if test="curPage==null||curPage==0">
<@s.if test="#item==1">
${item}
</@s.if>
<@s.else>
<a href="tradeList.action?startDate=<@s.property value="startDate"/>&endDate=<@s.property value="endDate"/>&curPage=${item}">[${item}]</a>
</@s.else>
</@s.if>
<@s.else>
<@s.if test="#item==curPage">
${item}
</@s.if>
<@s.else>
<a href="tradeList.action?startDate=<@s.property value="startDate"/>&endDate=<@s.property value="endDate"/>&curPage=${item}">[${item}]</a>
</@s.else>
</@s.else>
</@s.iterator>
</@s.if><@s.if test="totalPage>0">
<@s.iterator var="item" begin="1" end="totalPage">
<@s.if test="curPage==null||curPage==0">
<@s.if test="#item==1">
${item}
</@s.if>
<@s.else>
<a href="tradeList.action?startDate=<@s.property value="startDate"/>&endDate=<@s.property value="endDate"/>&curPage=${item}">[${item}]</a>
</@s.else>
</@s.if>
<@s.else>
<@s.if test="#item==curPage">
${item}
</@s.if>
<@s.else>
<a href="tradeList.action?startDate=<@s.property value="startDate"/>&endDate=<@s.property value="endDate"/>&curPage=${item}">[${item}]</a>
</@s.else>
</@s.else>
</@s.iterator>
</@s.if>