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


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


    網站導航:
     
    主站蜘蛛池模板: 毛片免费全部播放无码| 免费看大黄高清网站视频在线| 亚洲永久中文字幕在线| 天天摸天天碰成人免费视频| 在线播放国产不卡免费视频 | 亚洲AV无码不卡无码| 18女人腿打开无遮掩免费| 亚洲1区2区3区精华液| 在线v片免费观看视频| 高潮毛片无遮挡高清免费视频| 成人无遮挡毛片免费看| xxxxxx日本处大片免费看| 免费大学生国产在线观看p| 国产免费一区二区视频| 中文字幕乱码亚洲无线三区| 亚洲色偷偷综合亚洲AVYP| j8又粗又长又硬又爽免费视频 | 亚洲高清无码专区视频| 曰批全过程免费视频播放网站 | 久久国产精品成人片免费| 校园亚洲春色另类小说合集 | 久久免费香蕉视频| 中文字幕亚洲综合久久菠萝蜜| 免费在线观看h片| 久久精品成人免费观看97| 亚洲天然素人无码专区| 久久久影院亚洲精品| 99re6在线精品视频免费播放 | 亚洲国产精品白丝在线观看| 色噜噜亚洲精品中文字幕| 精品无码国产污污污免费| 日韩免费高清大片在线| 精品国产免费一区二区三区| 又黄又爽一线毛片免费观看| 亚洲精品久久无码av片俺去也 | 国产亚洲一区二区手机在线观看 | 水蜜桃亚洲一二三四在线| 亚洲精品国产高清不卡在线| 妞干网手机免费视频| 亚洲网站在线免费观看| 毛片在线全部免费观看|