天天看點

java程式實作分頁功能_java中實作分頁功能

package swing.login; import java.util.Vector; //傳入一個大的集合,取出一個小的集合 public class PageController { private Vector> bigv ;//定義一個大的集合,裝載傳過來的所有資料 private Vector> smallv = new Vector>();//定義一個小集合,裝載需要查詢到的資料 private static int curentPageIndex = 1;//設定目前頁數為第一頁 private int countPerpage;//每頁顯示的資料條數 private int pageCount;//總頁數 public PageController(){ } //定義帶參的構造方法,可傳入要分頁顯示的資料以及每頁顯示的條數 public PageController(Vector> v,int countPerpage){ this.bigv = v; //this.bigv = new EmpinfoDAO().select3(); this.countPerpage = countPerpage;//傳入每頁顯示的資料條數 if(bigv.size()%countPerpage==0){//設定頁數 this.pageCount = bigv.size()/countPerpage; }else{ this.pageCount = (bigv.size()/countPerpage)+1; } }// //首頁 public Vector> setCurentPageIndex(){ curentPageIndex =  1; return select(); } //上一頁 public Vector> previousPage(){ if(curentPageIndex > 1){ curentPageIndex--; //System.out.println("目前頁:"+curentPageIndex); } return select(); }// //下一頁 public Vector> nextPage(){ if(curentPageIndex < pageCount){ curentPageIndex++; //System.out.println("目前頁:"+curentPageIndex); } return select(); }// //末頁 public Vector> lastPage(){ curentPageIndex =  pageCount; return select(); }// //根據目前頁,篩選記錄 public Vector> select(){ //i從上一頁的最後一條開始(不包括最後一條,即本頁的第一條),i