科技行者

行者学院 转型私董会 科技行者专题报道 网红大战科技行者

知识库

知识库 安全导航

至顶网软件频道struts开发实践―分页的实现

struts开发实践―分页的实现

  • 扫一扫
    分享文章到微信

  • 扫一扫
    关注官方公众号
    至顶头条

本案主要功能是完成数据集的分页显示。示例代码如下: 1.PageInfo类:定义分页信息。

作者:中国IT实验室 来源:中国IT实验室 2007年9月24日

关键字:

在本页阅读全文(共2页)

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

    }

  }

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

<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">

...//省略

查看本文来源

    邮件订阅

    如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。

    重磅专题
    往期文章
    最新文章