有關java編程

          zodiac的學習筆記

          統計

          留言簿(1)

          閱讀排行榜

          評論排行榜

          一個通用的查詢結果頁面對象

          通常,此類對象放在項目的vo包中。
          PageBean.java代碼:
          package org.zodiac.vo;

          import java.util.List;

          /**查詢結果頁面對象
           * 
           
          */

          public class PageBean {

              
          private static final long serialVersionUID = 8167148510462280050L;

              
          private static Integer defaulfRowsPerPage = new Integer(50);

              
          private Integer rowsPerPage;

              
          private Integer currentPage;

              
          private Long totalRows;

              
          private Integer totalPages;

              
          private Integer startIndex;

              
          private Integer endIndex;

              
          private Integer nextPage;// 下一頁的頁碼

              
          private Integer previousPage;// 上一頁的頁碼

              
          private Boolean hasNextPage;// 是否有下一頁

              
          private Boolean hasPreviousPage;// 是否有前一頁

              
          private List<?> list;
              
              
          private IQueryCondition queryCondition;//查詢條件對象

              
          public PageBean(QueryCondition queryCondition) {
                  
          super();
                  
          this.queryCondition = queryCondition;
                  
                  
          if (queryCondition==null||queryCondition.getCurrentPage() == null{
                      
          this.currentPage = new Integer(1);
                  }
           else {
                      
          this.currentPage = queryCondition.getCurrentPage();
                  }

                  
          this.rowsPerPage = defaulfRowsPerPage;
              }


              
          public PageBean(Integer currentPage, Integer rowsPerPage) {
                  
          super();
                  
          if (currentPage == null{
                      
          this.currentPage = new Integer(1);
                  }
           else {
                      
          this.currentPage = currentPage;
                  }

                  
          if (rowsPerPage == null || rowsPerPage.intValue() < 1{
                      
          this.rowsPerPage = defaulfRowsPerPage;
                  }
           else {
                      
          this.rowsPerPage = rowsPerPage;
                  }

              }


              
          /**
               * 設置總數量,計算全部其他參數
               * 
               * 
          @param totalRows
               
          */

              
          public void setTotalRows(Long totalRows) {
                  
          this.totalRows = totalRows;

                  
          // 計算總頁數
                  if ((totalRows.longValue() % rowsPerPage.intValue()) == 0{
                      totalPages 
          = new Integer((int) (totalRows.longValue() / rowsPerPage.intValue()));
                  }
           else {
                      totalPages 
          = new Integer((int) (totalRows.longValue() / rowsPerPage.intValue() + 1));
                  }

                  
          // 計算下一頁
                  if (totalPages.compareTo(this.currentPage) > 0{
                      hasNextPage 
          = Boolean.TRUE;
                      nextPage 
          = new Integer(currentPage.intValue() + 1);
                  }
           else {
                      currentPage 
          = totalPages;
                      hasNextPage 
          = Boolean.FALSE;
                      nextPage 
          = totalPages;
                  }

                  
          // 計算上一頁
                  if (this.currentPage.intValue() > 1{
                      hasPreviousPage 
          = Boolean.TRUE;
                      previousPage 
          = new Integer(currentPage.intValue() - 1);
                  }
           else {
                      currentPage 
          = new Integer(1);
                      hasPreviousPage 
          = Boolean.FALSE;
                      previousPage 
          = new Integer(1);
                  }

                  
          // 計算當前頁的起止行
                  endIndex = new Integer(currentPage.intValue() * rowsPerPage.intValue());
                  startIndex 
          = new Integer(endIndex.intValue() - rowsPerPage.intValue() + 1);
              }


              
          public Integer getCurrentPage() {
                  
          return currentPage;
              }


              
          public Integer getEndIndex() {
                  
          return endIndex;
              }


              
          public Boolean getHasNextPage() {
                  
          return hasNextPage;
              }


              
          public Boolean getHasPreviousPage() {
                  
          return hasPreviousPage;
              }


              
          public Integer getNextPage() {
                  
          return nextPage;
              }


              
          public Integer getPreviousPage() {
                  
          return previousPage;
              }


              
          public Integer getRowsPerPage() {
                  
          return rowsPerPage;
              }


              
          public Integer getStartIndex() {
                  
          return startIndex;
              }


              
          public Integer getTotalPages() {
                  
          return totalPages;
              }


              
          public Long getTotalRows() {
                  
          return totalRows;
              }


              
          public List<?> getList() {
                  
          return list;
              }


              
          public void setList(List<?> list) {
                  
          this.list = list;
              }


              
          public IQueryCondition getQueryCondition() {
                  
          return queryCondition;
              }


              
          public void setQueryCondition(IQueryCondition queryCondition) {
                  
          this.queryCondition = queryCondition;
              }


          }


          IQueryCondition的實現就不羅嗦了。

          posted on 2008-12-24 15:01 Zodiac 閱讀(210) 評論(0)  編輯  收藏


          只有注冊用戶登錄后才能發表評論。


          網站導航:
          博客園   IT新聞   Chat2DB   C++博客   博問  
           
          主站蜘蛛池模板: 恩平市| 长岛县| 卢氏县| 奎屯市| 肇庆市| 庆元县| 德江县| 乌海市| 广州市| 龙川县| 宁河县| 星座| 澄江县| 沐川县| 台南县| 四子王旗| 沙田区| 贡嘎县| 邹城市| 巨野县| 卢龙县| 永福县| 浙江省| 万山特区| 邹平县| 潞城市| 韶山市| 金秀| 静安区| 丰都县| 宁蒗| 海安县| 遂溪县| 金昌市| 塘沽区| 交城县| 鄂尔多斯市| 遵化市| 承德市| 若羌县| 洪洞县|