知识大全 struts开发实践—分页的实现
Posted 知
篇首语:只有受过教育的人才是自由的。本文由小常识网(cha138.com)小编为大家整理,主要介绍了知识大全 struts开发实践—分页的实现相关的知识,希望对你有一定的参考价值。
本案主要功能是完成数据集的分页显示 示例代码如下
PageInfo类 定义分页信息
/******************program begin**************************/
package test;
import java io *;
public final class PaginationInfo
implements Serializable
/**页大小描述每页有多少行*/
private int pageSize = ;
/**是否有上一页*/
private boolean hasPrevious;
/**是否有下一页*/
private boolean hasNext;
/**总行数 */
private int total;
/**总页数 */
private int totalPage;
/**当前页码*/
private int currentPageNumber= ;
/**跳转动作 :首页 前一页 后一页 末页*/
private int jumpState;
public void setPageSize(int pageSize)
this pageSize = pageSize;
public int getPageSize()
return pageSize;
public void setHasPrevious(boolean hasPrevious)
this hasPrevious = hasPrevious;
public boolean getHasPrevious()
return hasPrevious;
public void setPreviousPageNumber(int previousPageNumber)
this previousPageNumber = previousPageNumber;
public int getPreviousPageNumber()
return previousPageNumber;
public void setHasNext(boolean hasNext)
this hasNext = hasNext;
public boolean getHasNext()
return hasNext;
public void setNextPageNumber(int nextPageNumber)
this nextPageNumber = nextPageNumber;
public int getNextPageNumber()
return nextPageNumber;
public void setTotal(int total)
this total = total;
public int getTotal()
return total;
public void setTotalPage(int totalPage)
this totalPage=totalPage;
public int getTotalPage()
return totalPage;
public void setCurrentPageNumber(int currentPageNumber)
this currentPageNumber=currentPageNumber;
public int getCurrentPageNumber()
return currentPageNumber;
public void setJumpState(int jumpState)
this jumpState=jumpState;
public int getJumpState()
return jumpState;
分页逻辑方法代码节选
public void setPageInfo(PaginationInfo paginationInfo)
//跳转页
if (paginationInfo getJumpState() == ) //首页
paginationInfo setCurrentPageNumber( );
if (paginationInfo getJumpState() == )
paginationInfo setCurrentPageNumber(paginationInfo getCurrentPageNumber()
);
if (paginationInfo getJumpState() == )
paginationInfo setCurrentPageNumber(paginationInfo getCurrentPageNumber() +
);
if (paginationInfo getJumpState() == )
paginationInfo setCurrentPageNumber(paginationInfo getTotalPage());
int totalPage = total / paginationInfo getPageSize();
if (total % paginationInfo getPageSize() > )
paginationInfo setTotalPage(totalPage + );
else
paginationInfo setTotalPage(totalPage);
if (paginationInfo getCurrentPageNumber() <= )
paginationInfo setCurrentPageNumber( );
paginationInfo setHasPrevious(false);
paginationInfo setHasNext(true);
else if (paginationInfo getCurrentPageNumber() >=
paginationInfo getTotalPage())
paginationInfo setCurrentPageNumber(paginationInfo getTotalPage());
paginationInfo setHasNext(false);
paginationInfo setHasPrevious(true);
else
paginationInfo setHasPrevious(true);
paginationInfo setHasNext(true);
jsp页面的分页显示代码节选
<logic:equal name= testForm property= paginationInfo currentPageNumber value= >
<td align= right width= height= ><img src= images/pages/distop gif alt= 首页 border= ></td>
<td align= right width= height= ><img src= images/pages/disprevious gif alt= 上一页 border= ></td>
</logic:equal>
<logic:greaterThan name= testForm property= paginationInfo currentPageNumber value= >
<td align= right width= height= ><a javascript:gotoPage( ) ><img src= images/pages/top gif alt= 首页 border= ></a></td>
<td align= right width= height= ><a javascript:gotoPage( ) ><img src= images/pages/previous gif alt= 上一页 border= ></a></td>
</logic:greaterThan>
<logic:equal name= testForm property= paginationInfo hasNext value= false >
<td align= right width= height= ><img src= images/pages/disnext gif alt= 下一页 border= ></td>
<td align= right width= height= ><img src= images/pages/disbottom gif alt= 末页 border= ></td>
</logic:equal>
<logic:equal name= testForm property= paginationInfo hasNext value= true >
<td align= right width= height= ><a javascript:gotoPage( ) ><img src= images/pages/next gif alt= 下一页 border= ></a></td>
<td align= right width= height= ><a javascript:gotoPage( ) ><img src= images/pages/bottom gif alt= 末页 border= ></a></td>
</logic:equal>
<:hidden name= testForm property= paginationInfo jumpState >
相关参考