<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 閱讀(333) 評論(0)  編輯  收藏


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


    網站導航:
     
    主站蜘蛛池模板: 国产免费网站看v片在线| 亚洲中文无码av永久| 蜜臀亚洲AV无码精品国产午夜.| 日韩亚洲国产高清免费视频| 久久久久无码专区亚洲av| 亚洲AV无码片一区二区三区| 无码国模国产在线观看免费| 蜜芽亚洲av无码一区二区三区| 日本免费一区二区三区最新vr| 亚洲av无码兔费综合| 四虎AV永久在线精品免费观看| 国产AV无码专区亚洲AV琪琪| 少妇亚洲免费精品| 青青草国产免费久久久91| 亚洲视频一区二区三区四区| 免费看片免费播放| 国产精品亚洲专区在线播放| 免费一级做a爰片性色毛片| 国产福利在线观看永久免费| 亚洲日本乱码在线观看| 99久久免费看国产精品| 亚洲娇小性xxxx| 香蕉视频在线观看免费国产婷婷| 最好2018中文免费视频| 亚洲精品无码AV人在线播放| 99爱免费观看视频在线| 国产精品亚洲四区在线观看| 免费一级特黄特色大片在线| 在线免费观看伊人三级电影| 亚洲性色成人av天堂| 国产18禁黄网站免费观看| 99精品视频在线观看免费| 亚洲老熟女@TubeumTV| 免费无码一区二区三区蜜桃大| 免费播放国产性色生活片| 亚洲va无码专区国产乱码| 99久久久国产精品免费无卡顿| 青娱乐在线视频免费观看| 久久久久亚洲AV成人片| 国产黄色片在线免费观看| a毛片免费全部在线播放**|