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

首頁 > 編程 > JSP > 正文

jsp分頁的實(shí)現(xiàn)方法

2024-09-05 00:18:30
字體:
供稿:網(wǎng)友

我們?cè)陂_發(fā)過程中數(shù)據(jù)分頁是必不可少的,但是由于數(shù)據(jù)量太大,因此我們不得不進(jìn)行處理,而分頁的方式有很多,我們應(yīng)該如何選擇呢?現(xiàn)在我們就去看看jsp分頁的實(shí)現(xiàn)方法。

分頁的實(shí)現(xiàn)方式我們可以使用sql語句的limit,或者使用jquery的插件。但是底層的邏輯,都是需要的。
在這里貼出bean對(duì)象的代碼,以及一個(gè)輔助類。我做的這個(gè)項(xiàng)目是一個(gè)個(gè)人博客,算是個(gè)人網(wǎng)站吧。

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

Page.java

package cn.edu.ldu.util;public class Page {  private int everyPage;     //每頁顯示的數(shù)量  private int totalPage;     //總頁數(shù)  private int totalCount;     //總數(shù)量  private int currentPage;    //當(dāng)前頁  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 {  //創(chuàng)建分頁信息對(duì)象  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);  }  //獲得每頁顯示記錄數(shù)  public static int getEveryPage(int everyPage) {    return everyPage == 0 ? 10 : everyPage;  }  //獲得當(dāng)前頁  public static int getCurrentPage(int currentPage) {    return currentPage == 0 ? 10 : currentPage;  }  //獲得總頁數(shù)  public static int getTotalPage(int everyPage,int totalCount) {    int totalPage=0;    //要判斷每頁是否滿頁,否則頁數(shù)+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;  }}

每次我只需要去調(diào)用即可。

//傳入每頁顯示的頁數(shù),總記錄數(shù),當(dāng)前頁P(yáng)age page=PageUtil.createPage(5, diaryDao.findAllCount(), currentPage);

以上就是jsp分頁的實(shí)現(xiàn)方法,具有一定的參考和學(xué)習(xí)JSP的價(jià)值,對(duì)JSP感興趣的小伙伴們可以參考一下本篇文章。

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 蒙阴县| 南投县| 尚志市| 区。| 定西市| 商南县| 澄江县| 庆城县| 乌兰察布市| 台中市| 汾阳市| 曲阳县| 峨边| 嵩明县| 资阳市| 南宫市| 大洼县| 肇州县| 买车| 金堂县| 兴国县| 司法| 通城县| 乐都县| 石狮市| 中卫市| 敖汉旗| 砀山县| 江门市| 仪陇县| 岗巴县| 两当县| 嵩明县| 麻城市| 卫辉市| 望江县| 萨迦县| 商城县| 容城县| 开原市| 邹平县|