熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> Java編程 >> Java開源技術 >> 正文

struts開發實踐—分頁的實現

2013-11-23 20:16:50  來源: Java開源技術 

  本案主要功能是完成數據集的分頁顯示示例代碼如下

  

  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>

  //省略


From:http://tw.wingwit.com/Article/program/Java/ky/201311/28225.html
  • 上一篇文章:

  • 下一篇文章:
  • 推薦文章
    Copyright © 2005-2013 電腦知識網 Computer Knowledge   All rights reserved.