国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JSP > 正文

簡單實現jsp分頁

2024-09-05 00:22:47
字體:
來源:轉載
供稿:網友

數據分頁,在開發中必不可少,由于數據量太大,不得不進行處理。但是對于分頁,又有很多種方式,比如使用sql語句的limit,或者使用jquery的插件。但是底層的邏輯,都是需要的。
在這里貼出bean對象的代碼,以及一個輔助類。我做的這個項目是一個個人博客,算是個人網站吧。

(只貼部分底層邏輯代碼)

Page.java

package cn.edu.ldu.util;public class Page {  private int everyPage;     //每頁顯示的數量  private int totalPage;     //總頁數  private int totalCount;     //總數量  private int currentPage;    //當前頁  private int beginIndex;     //起始頁  private boolean hasPrepage;   //是否有上一頁  private boolean hasNextPage;  //是否有下一頁  public Page() {  }  public Page(int everyPage, int totalPage, int totalCount, int currentPage,int beginIndex, boolean hasPrepage, boolean hasNextPage)  {    this.everyPage = everyPage;    this.totalPage = totalPage;    this.totalCount = totalCount;    this.currentPage = currentPage;    this.beginIndex = beginIndex;    this.hasPrepage = hasPrepage;    this.hasNextPage = hasNextPage;  }  public int getEveryPage() {    return everyPage;  }  public void setEveryPage(int everyPage) {    this.everyPage = everyPage;  }  public int getTotalPage() {    return totalPage;  }  public void setTotalPage(int totalPage) {    this.totalPage = totalPage;  }  public int getTotalCount() {    return totalCount;  }  public void setTotalCount(int totalCount) {    this.totalCount = totalCount;  }  public int getCurrentPage() {    return currentPage;  }  public void setCurrentPage(int currentPage) {    this.currentPage = currentPage;  }  public int getBeginIndex() {    return beginIndex;  }  public void setBeginIndex(int beginIndex) {    this.beginIndex = beginIndex;  }  public boolean isHasPrepage() {    return hasPrepage;  }  public void setHasPrepage(boolean hasPrepage) {    this.hasPrepage = hasPrepage;  }  public boolean isHasNextPage() {    return hasNextPage;  }  public void setHasNextPage(boolean hasNextPage) {    this.hasNextPage = hasNextPage;  }}

PageUtil.java

package cn.edu.ldu.util;public class PageUtil {  //創建分頁信息對象  public static Page createPage(int everyPage,int totalCount,int currentPage) {    everyPage = getEveryPage(everyPage);    currentPage = getCurrentPage(currentPage);    int totalPage = getTotalPage(everyPage, totalCount);    int beginIndex = getBeginIndex(everyPage, currentPage);    boolean hasPrePage = getHasPrePage(currentPage);    boolean hasNextPage = getHasNextPage(totalPage, currentPage);    return new Page(everyPage, totalPage,totalCount, currentPage,        beginIndex, hasPrePage, hasNextPage);  }  //獲得每頁顯示記錄數  public static int getEveryPage(int everyPage) {    return everyPage == 0 ? 10 : everyPage;  }  //獲得當前頁  public static int getCurrentPage(int currentPage) {    return currentPage == 0 ? 10 : currentPage;  }  //獲得總頁數  public static int getTotalPage(int everyPage,int totalCount) {    int totalPage=0;    //要判斷每頁是否滿頁,否則頁數+1    if(totalCount!=0 && totalCount%everyPage==0) {      totalPage=totalCount/everyPage;    }    else {      totalPage=totalCount/everyPage+1;    }    return totalPage;  }  //獲得起始位置  public static int getBeginIndex(int everyPage,int currentPage) {    return everyPage*(currentPage-1);  }  //判斷是否有上一頁  public static boolean getHasPrePage(int currentPage) {    return currentPage== 1 ? false : true;  }  //判斷是否有下一頁  public static boolean getHasNextPage(int totalPage, int currentPage) {    return (currentPage == totalPage) || (totalPage == 0) ? false : true;  }}

每次我只需要去調用即可。

//傳入每頁顯示的頁數,總記錄數,當前頁Page page=PageUtil.createPage(5, diaryDao.findAllCount(), currentPage);

jsp,分頁

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持VeVb武林網。


注:相關教程知識閱讀請移步到JSP教程頻道。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 洛扎县| 衡南县| 石屏县| 泽库县| 禄丰县| 平湖市| 锦州市| 治多县| 航空| 龙山县| 武宣县| 乌兰察布市| 禹州市| 武汉市| 梁平县| 达州市| 枣强县| 丰镇市| 车险| 江口县| 潼南县| 白山市| 无为县| 兰溪市| 巍山| 祁连县| 溧水县| 翁源县| 北碚区| 类乌齐县| 万州区| 井研县| 平顺县| 铜梁县| 永兴县| 剑阁县| 岗巴县| 调兵山市| 阳东县| 嘉义县| 姜堰市|