分頁頁碼顯示演算法

來源:互聯網
上載者:User

---這不是分頁演算法,而是頁碼顯示的演算法。

看:

這個是分好頁之後,頁碼比較多的時候,可以用這個演算法實現這種效果

轉載請註明來源,by-潘敬

代碼:

package com.domain;public class PageCode {int pageCount = 0; // 頁碼數量int showCount = 0; // 顯示數量int begin = 0; // 開始位置int end = 0; // 結束位置int index=0;// 索引public PageCode() {}/** * 傳入顯示的頁碼數量和每頁顯示的數量和當前頁的索引 * @param pageCount * @param showCount * @param index */public PageCode(int pageCount, int showCount, int index) {super();this.pageCount = pageCount;this.showCount = showCount;this.index = index>pageCount?pageCount:index;System.out.println("index:"+this.index);//進行計算int number=showCount/2;int last=number%2;if(last!=0){this.begin=this.index-number;this.end=this.index+number;}else{this.begin=this.index-number-1;this.end=this.index+number;}//計算啟示和結束的值 不允許負數和超出//如果begin為負數 就取絕對值給endif(begin<0){end+=Math.abs(begin);begin=end-showCount;}//如果end大於總頁數 就等於總頁數if(end>pageCount){end=pageCount;}//頁碼從1開始begin+=1;//保留第一頁和最後一頁begin+=1;end=end+1<pageCount?end+1:pageCount-1;}public int getPageCount() {return pageCount;}public void setPageCount(int pageCount) {this.pageCount = pageCount;}public int getShowCount() {return showCount;}public void setShowCount(int showCount) {this.showCount = showCount;}public int getBegin() {return begin;}public void setBegin(int begin) {this.begin = begin;}public int getEnd() {return end;}public void setEnd(int end) {this.end = end;}public int getIndex() {return index;}public void setIndex(int index) {this.index = index;}}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.