佳木斯湛栽影视文化发展公司

主頁(yè) > 知識(shí)庫(kù) > 簡(jiǎn)單實(shí)現(xiàn)jsp分頁(yè)

簡(jiǎn)單實(shí)現(xiàn)jsp分頁(yè)

熱門標(biāo)簽:科大訊飛語(yǔ)音識(shí)別系統(tǒng) 團(tuán)購(gòu)網(wǎng)站 Mysql連接數(shù)設(shè)置 阿里云 服務(wù)器配置 銀行業(yè)務(wù) 電子圍欄 Linux服務(wù)器

數(shù)據(jù)分頁(yè),在開(kāi)發(fā)中必不可少,由于數(shù)據(jù)量太大,不得不進(jìn)行處理。但是對(duì)于分頁(yè),又有很多種方式,比如使用sql語(yǔ)句的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;     //每頁(yè)顯示的數(shù)量
  private int totalPage;     //總頁(yè)數(shù)
  private int totalCount;     //總數(shù)量
  private int currentPage;    //當(dāng)前頁(yè)
  private int beginIndex;     //起始頁(yè)
  private boolean hasPrepage;   //是否有上一頁(yè)
  private boolean hasNextPage;  //是否有下一頁(yè)

  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)建分頁(yè)信息對(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);
  }

  //獲得每頁(yè)顯示記錄數(shù)
  public static int getEveryPage(int everyPage) {
    return everyPage == 0 ? 10 : everyPage;
  }

  //獲得當(dāng)前頁(yè)
  public static int getCurrentPage(int currentPage) {
    return currentPage == 0 ? 10 : currentPage;
  }

  //獲得總頁(yè)數(shù)
  public static int getTotalPage(int everyPage,int totalCount) {
    int totalPage=0;
    //要判斷每頁(yè)是否滿頁(yè),否則頁(yè)數(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);
  }

  //判斷是否有上一頁(yè)
  public static boolean getHasPrePage(int currentPage) {
    return currentPage== 1 ? false : true;

  }

  //判斷是否有下一頁(yè)
  public static boolean getHasNextPage(int totalPage, int currentPage) {
    return (currentPage == totalPage) || (totalPage == 0) ? false : true;
  }

}


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

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

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

您可能感興趣的文章:
  • JSP分頁(yè)顯示的實(shí)例代碼
  • jsp分頁(yè)顯示的實(shí)現(xiàn)代碼
  • 一個(gè)實(shí)用的JSP分頁(yè)代碼
  • jsp hibernate的分頁(yè)代碼
  • 一個(gè)通用的jsp分頁(yè)P(yáng)ageBean
  • JSP自定義分頁(yè)標(biāo)簽TAG全過(guò)程
  • jsp讀取數(shù)據(jù)庫(kù)實(shí)現(xiàn)分頁(yè)技術(shù)簡(jiǎn)析
  • JSP實(shí)現(xiàn)的簡(jiǎn)單分頁(yè)示例
  • json實(shí)現(xiàn)jsp分頁(yè)實(shí)例介紹(附效果圖)
  • jsp+servlet+javabean實(shí)現(xiàn)數(shù)據(jù)分頁(yè)方法完整實(shí)例

標(biāo)簽:萍鄉(xiāng) 棗莊 衡水 廣元 衢州 江蘇 蚌埠 大理

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《簡(jiǎn)單實(shí)現(xiàn)jsp分頁(yè)》,本文關(guān)鍵詞  ;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問(wèn)題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無(wú)關(guān)。
  • 相關(guān)文章
  • 收縮
    • 微信客服
    • 微信二維碼
    • 電話咨詢

    • 400-1100-266
    长兴县| 海城市| 同德县| 建湖县| 家居| 华安县| 麦盖提县| 桑日县| 高陵县| 宿州市| 天全县| 旬邑县| 锡林浩特市| 理塘县| 洛扎县| 阿坝| 都江堰市| 都安| 海晏县| 且末县| 保山市| 宜兰县| 昌都县| 大渡口区| 福安市| 云林县| 和硕县| 平原县| 康平县| 刚察县| 桑植县| 望江县| 衢州市| 巍山| 珠海市| 航空| 商城县| 酉阳| 时尚| 松桃| 陇川县|