分享
 
 
 

struts开发实践—分页的实现

王朝other·作者佚名  2007-02-06
窄屏简体版  字體: |||超大  

--文章源自一位网友

struts开发实践-分页的实现

本案主要功能是完成数据集的分页显示。示例代码如下:

1.PageInfo类:定义分页信息。

/******************program begin**************************/

package test;

import java.io.*;

public final class PaginationInfo

implements Serializable {

/**页大小描述每页有多少行*/

private int pageSize = 20;

/**是否有上一页*/

private boolean hasPrevious;

/**是否有下一页*/

private boolean hasNext;

/**总行数 */

private int total;

/**总页数 */

private int totalPage;

/**当前页码*/

private int currentPageNumber=1;

/**跳转动作:1:首页;2:前一页;3:后一页;4:末页*/

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;

}

}

2.分页逻辑方法代码节选:

public void setPageInfo(PaginationInfo paginationInfo) {

//跳转页

if (paginationInfo.getJumpState() == 1) { //首页

paginationInfo.setCurrentPageNumber(1);

}

if (paginationInfo.getJumpState() == 2) {

paginationInfo.setCurrentPageNumber(paginationInfo.getCurrentPageNumber() -

1);

}

if (paginationInfo.getJumpState() == 3) {

paginationInfo.setCurrentPageNumber(paginationInfo.getCurrentPageNumber() +

1);

}

if (paginationInfo.getJumpState() == 4) {

paginationInfo.setCurrentPageNumber(paginationInfo.getTotalPage());

}

int totalPage = total / paginationInfo.getPageSize();

if (total % paginationInfo.getPageSize() > 0) {

paginationInfo.setTotalPage(totalPage + 1);

}

else {

paginationInfo.setTotalPage(totalPage);

}

if (paginationInfo.getCurrentPageNumber() <= 1) {

paginationInfo.setCurrentPageNumber(1);

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);

}

}

3。jsp页面的分页显示代码节选:

<logic:equal name="testForm" property="paginationInfo.currentPageNumber" value="1">

<td align="right" width="30" height="22"><img src="images/pages/distop.gif" alt="首页" border="0"></td>

<td align="right" width="30" height="22"><img src="images/pages/disprevious.gif" alt="上一页" border="0" ></td>

</logic:equal>

<logic:greaterThan name="testForm" property="paginationInfo.currentPageNumber" value="1">

<td align="right" width="30" height="22"><a href="javascript:gotoPage(1)"><img src="images/pages/top.gif" alt="首页" border="0" ></a></td>

<td align="right" width="30" height="22"><a href="javascript:gotoPage(2)"><img src="images/pages/previous.gif" alt="上一页" border="0"></a></td>

</logic:greaterThan>

<logic:equal name="testForm" property="paginationInfo.hasNext" value="false">

<td align="right" width="30" height="22"><img src="images/pages/disnext.gif" alt="下一页" border="0" ></td>

<td align="right" width="30" height="22"><img src="images/pages/disbottom.gif" alt="末页" border="0" ></td>

</logic:equal>

<logic:equal name="testForm" property="paginationInfo.hasNext" value="true">

<td align="right" width="30" height="22"><a href="javascript:gotoPage(3)"><img src="images/pages/next.gif" alt="下一页" border="0" ></a></td>

<td align="right" width="30" height="22"><a href="javascript:gotoPage(4)"><img src="images/pages/bottom.gif" alt="末页" border="0"></a></td>

</logic:equal>

<html:hidden name="testForm" property="paginationInfo.jumpState">

...//省略

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有