<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    athrunwang

    紀元
    數據加載中……
    分頁欄

    DAO層的代碼分頁代碼:
    public PageModel findByPageModel(String hql,PageModel pm) {
      pm.setTotalCount(this.getHibernateTemplate().find(hql).size());
      pm.setGoToHref(ServletActionContext.getRequest().getServletPath().replace("/",""));
      int totalCount = pm.getTotalCount();
      int pageSize = pm.getPageSize();
      int totalPage = (totalCount+pageSize-1)/pageSize ;
      int currentPage = pm.getCurrentPage() ;
      pm.setTotalPage(totalPage);
      int offset = (currentPage-1)*pageSize;
      pm.setList(this.getSession().createQuery(hql).setFirstResult(offset).setMaxResults(pageSize).list());
      return pm;
     }


    分頁的JAVABEAN:
    public class PageModel {
     private int currentPage;
     private int pageSize;
     private int totalCount;
     private int totalPage;
     private List list ;
     private String goToHref;
     
     public int getCurrentPage() {
      if(currentPage<=0) currentPage=1;
      return currentPage;
     }
     public void setCurrentPage(int currentPage) {
      this.currentPage = currentPage;
     }
     public int getPageSize() {
      if(pageSize<=0) pageSize=10;
      return pageSize;
     }
     public void setPageSize(int pageSize) {
      this.pageSize = pageSize;
     }
     public int getTotalCount() {
      return totalCount;
     }
     public void setTotalCount(int totalCount) {
      this.totalCount = totalCount;
     }
     public int getTotalPage() {
      return totalPage;
     }
     public void setTotalPage(int totalPage) {
      this.totalPage = totalPage;
     }
     public List getList() {
      return list;
     }
     public void setList(List list) {
      this.list = list;
     }
     public String getGoToHref() {
      return goToHref;
     }
     public void setGoToHref(String goToHref) {
      this.goToHref = goToHref;
     }
    }


    JSP頁面:
    <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
    <%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
    %>

    <link rel="stylesheet" type="text/css" href="<%=basePath %>findByHql/pagingBar/css/pagingBar.css">

     <input type="button" class="firstPage commonPage"  alt="首頁"   title="首頁"/>
     <input type="button" class="beforePage commonPage" alt="上一頁" title="上一頁"/>
     <input type="button" class="nextPage commonPage"   alt="下一頁" title="下一頁"/>
     <input type="button" class="lastPage commonPage"   alt="尾頁"   title="尾頁" />
     
     <input type="hidden" id="currentPage" value="${requestScope.pm.currentPage }" />
     <input type="hidden" id="totalPage" value="${requestScope.pm.totalPage }" />
     <input type="hidden" id="goToHref" value="${requestScope.pm.goToHref }" />
     
     <span class="cp">當前第${requestScope.pm.currentPage }頁</span>
     <span class="tc"> 相關資訊:${requestScope.pm.totalCount }條</span>
     <span class="ps">每頁${requestScope.pm.pageSize }條 </span>
     <span class="tp">共${requestScope.pm.totalPage}頁</span>

    <script type="text/javascript" src="<%=basePath%>js/jquery.js"></script>
    <script type="text/javascript">
     (function($) {
      var currentPage = parseInt($('#currentPage').val());
      var totalPage = parseInt($('#totalPage').val());
      var toHref = $('#goToHref').val();
      $('.firstPage').bind('click', function() {
       goToHref(1);
      });
      $('.nextPage').bind('click', function() {
       if (currentPage >= totalPage)
        goToHref(totalPage);
       else
        goToHref(currentPage + 1);
      });
      $('.beforePage').bind('click', function() {
       if (currentPage <= 1)
        goToHref(1);
       else
        goToHref(currentPage - 1);
      });
      $('.lastPage').bind('click', function() {
       goToHref(totalPage);
      });
      function goToHref(cp) {
       document.location.href = toHref+"?currentPage=" + cp;
      }
     })(jQuery)
    </script>


    CSS:下面有幾張圖片需要自己找...
    /*點擊欄*/
    .commonPage{
     width: 16px;
     height: 16px;
     border: none;
     cursor: pointer;
    }
    .firstPage{
     background: url("../images/page-first.png") no-repeat;
    }

    .nextPage{
     background: url("../images/page-next.png") no-repeat;
    }

    .beforePage{
     background: url("../images/page-prev.png") no-repeat;
    }

    .lastPage{
     background: url("../images/page-last.png") no-repeat;
    }

    /*顯示欄*/
    .cp,.tc,.ps,.tp{
     font-size: 14px;
    }

    在action中調用DAO層的方法,給currentPage和pageSize設置初始值,然后就返回一個list到你分頁的頁面迭代,以后就直接嵌套在分頁頁面中就行

    posted on 2012-03-27 10:19 AthrunWang 閱讀(331) 評論(0)  編輯  收藏


    只有注冊用戶登錄后才能發表評論。


    網站導航:
     
    主站蜘蛛池模板: 亚洲中文字幕在线无码一区二区 | 国产aⅴ无码专区亚洲av| 亚洲老熟女五十路老熟女bbw| 国产人成免费视频网站| 亚洲沟沟美女亚洲沟沟| 我们的2018在线观看免费高清| 亚洲春色另类小说| 久久不见久久见免费影院| 亚洲综合无码无在线观看| 国产乱人免费视频| 免费无码婬片aaa直播表情| 亚洲成人国产精品| 爱丫爱丫影院在线观看免费| 亚洲日本一区二区| 人成午夜免费视频在线观看| 亚洲kkk4444在线观看| 免费大黄网站在线观| 国产特黄一级一片免费| 亚洲va在线va天堂va888www| 四虎在线成人免费网站| 亚洲乱理伦片在线观看中字| 亚洲欧洲日产国码高潮αv| 成全视频免费观看在线看| 亚洲人成综合在线播放| 免费看一级做a爰片久久| 三年片在线观看免费西瓜视频| 亚洲视频日韩视频| 国产精品99久久免费| 中文字幕在线免费观看视频| 久久久亚洲欧洲日产国码aⅴ | 久久久国产亚洲精品| jizzjizz亚洲| 91精品国产免费| 99亚洲男女激情在线观看| 亚洲AV无码久久精品成人| 成年女人毛片免费播放人| 99久久成人国产精品免费| tom影院亚洲国产一区二区| 亚洲国产精品国产自在在线 | 日本黄色免费观看| 中文成人久久久久影院免费观看|