最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

簡單實現(xiàn)jsp分頁

 更新時間:2016年12月15日 08:35:36   作者:hlk_1135  
這篇文章主要為大家詳細介紹了如何簡單實現(xiàn)jsp分頁,具有一定的參考價值,感興趣的小伙伴們可以參考一下

數(shù)據(jù)分頁,在開發(fā)中必不可少,由于數(shù)據(jù)量太大,不得不進行處理。但是對于分頁,又有很多種方式,比如使用sql語句的limit,或者使用jquery的插件。但是底層的邏輯,都是需要的。
在這里貼出bean對象的代碼,以及一個輔助類。我做的這個項目是一個個人博客,算是個人網(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)建分頁信息對象
  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)前頁
Page page=PageUtil.createPage(5, diaryDao.findAllCount(), currentPage);

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論

东阳市| 射阳县| 明光市| 年辖:市辖区| 府谷县| 阜南县| 辽宁省| 霍邱县| 长寿区| 盈江县| 威海市| 大田县| 盐津县| 连城县| 临洮县| 武定县| 沾益县| 德江县| 韶山市| 新巴尔虎右旗| 肇东市| 江达县| 定襄县| 宿州市| 汉寿县| 新宾| 崇义县| 始兴县| 梁平县| 潞西市| 凤阳县| 静海县| 绍兴县| 乌海市| 崇礼县| 辽源市| 紫金县| 黄梅县| 肥东县| 临桂县| 德保县|