Java Blog for Alex Wan

          Let life be beautiful like summer flowers and death like autumn leaves.

          統(tǒng)計(jì)

          留言簿(10)

          BlogJava

          Blogs

          DIV+CSS

          JQuery相關(guān)

          友情鏈接

          常去的地方

          數(shù)據(jù)供應(yīng)

          閱讀排行榜

          評(píng)論排行榜

          java中簡(jiǎn)單的翻頁(yè)功能的實(shí)現(xiàn)(PageManager)

          package util;
          import java.util.List;

          public class PageManager
          {
              private List allRecords = null;//collection儲(chǔ)存同一類(lèi)型的對(duì)象的集合
              private int currentPage = 0;//當(dāng)前頁(yè)碼
              private int totalPage = 0;//總頁(yè)數(shù)
              private int recordPerPage = -1;//每頁(yè)的對(duì)象數(shù)
              private int totalCount=0;//總的對(duì)象數(shù)
           //初始化
           public PageManager(List allRecords, int recordPerPage)
              {
                  if (allRecords == null || recordPerPage < 1) return;

                  this.allRecords = allRecords;
                  this.recordPerPage = recordPerPage;
                  this.totalCount=allRecords.size();
                  if (allRecords.size() % recordPerPage == 0)
                      this.totalPage = allRecords.size() / recordPerPage;
                  else
                      this.totalPage = allRecords.size() / recordPerPage + 1;
                  this.currentPage = 0;
              }
              //獲取所有對(duì)象集合
              public List getAllRecords()
              {
               return this.allRecords;
              }
           //獲取當(dāng)前頁(yè)的的對(duì)象集合
              public List getCurrentPage()
              {
               return getPage(currentPage);
              }
              //根據(jù)序號(hào)獲取該對(duì)象所在的頁(yè)的對(duì)象集合
              public List getThePage(int recordno)
              {
               if (this.allRecords == null || this.allRecords.size() == 0)
                  {
                      this.currentPage = 0;
                      return null;
                  }
                  int pageNo=1;
                  if (recordno < 1) pageNo = 1;
                 
                  else if (recordno > this.allRecords.size())
                   pageNo = this.totalPage;
                  else
                  {
                   pageNo=recordno/this.recordPerPage+1;
                  }
                  this.currentPage = pageNo;
                 
                  int pageStart = (pageNo - 1) * this.recordPerPage;
                  int pageEnd = pageStart + this.recordPerPage - 1;
                  if (pageEnd > this.allRecords.size() - 1) pageEnd = this.allRecords.size() - 1;
                 
                  List result =this.allRecords.subList(pageStart, pageEnd+1);       
                  return result;
              }
             //根據(jù)頁(yè)碼獲取改頁(yè)的對(duì)象集合
              public List getPage(int pageNo)
              {
                  if (this.allRecords == null || this.allRecords.size() == 0)
                  {
                      this.currentPage = 0;
                      return null;
                  }
                 
                  if (pageNo < 1) pageNo = 1;
                  if (pageNo > this.totalPage) pageNo = this.totalPage;
                  this.currentPage = pageNo;
                 
                  int pageStart = (pageNo - 1) * this.recordPerPage;
                  int pageEnd = pageStart + this.recordPerPage - 1;
                  if (pageEnd > this.allRecords.size() - 1) pageEnd = this.allRecords.size() - 1;
                  List result =this.allRecords.subList(pageStart, pageEnd+1);
                  return result;
              }
              //獲取下一頁(yè)的對(duì)象集合
              public List getNextPage()
              {
                  return getPage(this.currentPage + 1);
              }
               //獲取上一頁(yè)的對(duì)象集合
              public List getPreviousPage()
              {
                  return getPage(this.currentPage - 1);
              }
             //獲取第一頁(yè)的對(duì)象集合 
              public List getFirstPage()
              {
                  return getPage(1);
              }
            //獲取最后一頁(yè)的對(duì)象集合
              public List getLastPage()
              {
                  return getPage(this.totalPage);
              }
             //獲取總頁(yè)數(shù)
           public int getTotalPage() {
            return totalPage;
           }
           //獲取當(dāng)前頁(yè)碼 
           public int getCurrentPageCount()
           {
            return this.currentPage;
           }
           //獲取對(duì)象總數(shù)
           public int getTotalCount() {
            return totalCount;
           }


          }



          Let life be beautiful like summer flowers and death like autumn leaves.

          posted on 2008-06-07 10:19 Alexwan 閱讀(2307) 評(píng)論(0)  編輯  收藏


          只有注冊(cè)用戶(hù)登錄后才能發(fā)表評(píng)論。


          網(wǎng)站導(dǎo)航:
           
          主站蜘蛛池模板: 尼勒克县| 乌拉特前旗| 葫芦岛市| 赫章县| 鲜城| 金阳县| 会理县| 通渭县| 九龙县| 泾川县| 瓦房店市| 樟树市| 黑水县| 会宁县| 平阳县| 米林县| 拉萨市| 囊谦县| 榆树市| 通海县| 靖西县| 新兴县| 蓬莱市| 定州市| 永德县| 信宜市| 磴口县| 凤翔县| 界首市| 基隆市| 荣成市| 共和县| 霍林郭勒市| 张掖市| 枣庄市| 改则县| 库伦旗| 诸暨市| 平原县| 泸州市| 甘德县|