本案主要功能是完成数据集的分页显示示例代码如下
PageInfo类定义分页信息
/******************program begin**************************/
package test;
import javaio*;
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) {
thispageSize = pageSize;
}
public int getPageSize() {
return pageSize;
}
public void setHasPrevious(boolean hasPrevious) {
thishasPrevious = hasPrevious;
}
public boolean getHasPrevious() {
return hasPrevious;
}
public void setPreviousPageNumber(int previousPageNumber) {
thispreviousPageNumber = previousPageNumber;
}
public int getPreviousPageNumber() {
return previousPageNumber;
}
public void setHasNext(boolean hasNext) {
thishasNext = hasNext;
}
public boolean getHasNext() {
return hasNext;
}
public void setNextPageNumber(int nextPageNumber) {
thisnextPageNumber = nextPageNumber;
}
public int getNextPageNumber() {
return nextPageNumber;
}
public void setTotal(int total) {
thistotal = total;
}
public int getTotal() {
return total;
}
public void setTotalPage(int totalPage) {
thistotalPage=totalPage;
}
public int getTotalPage() {
return totalPage;
}
public void setCurrentPageNumber(int currentPageNumber) {
thiscurrentPageNumber=currentPageNumber;
}
public int getCurrentPageNumber() {
return currentPageNumber;
}
public void setJumpState(int jumpState){
thisjumpState=jumpState;
}
public int getJumpState(){
return jumpState;
}
}
分页逻辑方法代码节选
public void setPageInfo(PaginationInfo paginationInfo) {
//跳转页
if (paginationInfogetJumpState() == ) { //首页
paginationInfosetCurrentPageNumber();
}
if (paginationInfogetJumpState() == ) {
paginationInfosetCurrentPageNumber(paginationInfogetCurrentPageNumber()
);
}
if (paginationInfogetJumpState() == ) {
paginationInfosetCurrentPageNumber(paginationInfogetCurrentPageNumber() +
);
}
if (paginationInfogetJumpState() == ) {
paginationInfosetCurrentPageNumber(paginationInfogetTotalPage());
}
int totalPage = total / paginationInfogetPageSize();
if (total % paginationInfogetPageSize() > ) {
paginationInfosetTotalPage(totalPage + );
}
else {
paginationInfosetTotalPage(totalPage);
}
if (paginationInfogetCurrentPageNumber() <= ) {
paginationInfosetCurrentPageNumber();
paginationInfosetHasPrevious(false);
paginationInfosetHasNext(true);
}
else if (paginationInfogetCurrentPageNumber() >=
paginationInfogetTotalPage()) {
paginationInfosetCurrentPageNumber(paginationInfogetTotalPage());
paginationInfosetHasNext(false);
paginationInfosetHasPrevious(true);
}
else {
paginationInfosetHasPrevious(true);
paginationInfosetHasNext(true);
}
}
jsp页面的分页显示代码节选
<logic:equal name=testForm property=paginationInfocurrentPageNumber value=>
<td align=right width= height=><img src=images/pages/distopgif alt=首页 border=></td>
<td align=right width= height=><img src=images/pages/dispreviousgif alt=上一页 border= ></td>
</logic:equal>
<logic:greaterThan name=testForm property=paginationInfocurrentPageNumber value=>
<td align=right width= height=><a javascript:gotoPage()><img src=images/pages/topgif alt=首页 border= ></a></td>
<td align=right width= height=><a javascript:gotoPage()><img src=images/pages/previousgif alt=上一页 border=></a></td>
</logic:greaterThan>
<logic:equal name=testForm property=paginationInfohasNext value=false>
<td align=right width= height=><img src=images/pages/disnextgif alt=下一页 border= ></td>
<td align=right width= height=><img src=images/pages/disbottomgif alt=末页 border= ></td>
</logic:equal>
<logic:equal name=testForm property=paginationInfohasNext value=true>
<td align=right width= height=><a javascript:gotoPage()><img src=images/pages/nextgif alt=下一页 border= ></a></td>
<td align=right width= height=><a javascript:gotoPage()><img src=images/pages/bottomgif alt=末页 border=></a></td>
</logic:equal>
<html:hidden name=testForm property=paginationInfojumpState>
//省略