<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)  編輯  收藏


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


    網站導航:
     
    主站蜘蛛池模板: 亚洲精品成人片在线播放| 亚洲天堂免费在线视频| 亚洲欧洲久久精品| 在线日本高清免费不卡| 亚洲国产国产综合一区首页| 伊人久久免费视频| 亚洲精品在线免费观看视频| 91九色精品国产免费| 亚洲中文字幕AV在天堂| 免费看片A级毛片免费看| 亚洲爆乳无码专区www| 免费播放春色aⅴ视频| 大妹子影视剧在线观看全集免费| 亚洲熟妇av一区二区三区漫画| 国产在线播放线91免费| 久久精品视频亚洲| 免费A级毛片无码无遮挡内射| 亚洲日韩看片无码电影| 四虎成人精品在永久免费| 成人精品视频99在线观看免费| 久久精品视频亚洲| 在线看片无码永久免费视频| 女bbbbxxxx另类亚洲| 国产亚洲美女精品久久久2020| 日韩av无码久久精品免费| 亚洲国产成a人v在线观看| 亚洲国产精品成人网址天堂| 日本中文字幕免费高清视频| 涩涩色中文综合亚洲| 亚洲女人被黑人巨大进入| 亚洲精品国产免费| 白白色免费在线视频| 久久精品国产亚洲av高清漫画 | 两个人www免费高清视频| 无码欧精品亚洲日韩一区| 久久精品无码一区二区三区免费| 一级黄色毛片免费看| 91亚洲视频在线观看| 国产中文在线亚洲精品官网| 无码av免费毛片一区二区| h片在线观看免费|