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

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

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

    athrunwang

    紀(jì)元
    數(shù)據(jù)加載中……
    分頁(yè)欄

    DAO層的代碼分頁(yè)代碼:
    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;
     }


    分頁(yè)的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頁(yè)面:
    <%@ 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="首頁(yè)"   title="首頁(yè)"/>
     <input type="button" class="beforePage commonPage" alt="上一頁(yè)" title="上一頁(yè)"/>
     <input type="button" class="nextPage commonPage"   alt="下一頁(yè)" title="下一頁(yè)"/>
     <input type="button" class="lastPage commonPage"   alt="尾頁(yè)"   title="尾頁(yè)" />
     
     <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">當(dāng)前第${requestScope.pm.currentPage }頁(yè)</span>
     <span class="tc"> 相關(guān)資訊:${requestScope.pm.totalCount }條</span>
     <span class="ps">每頁(yè)${requestScope.pm.pageSize }條 </span>
     <span class="tp">共${requestScope.pm.totalPage}頁(yè)</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:下面有幾張圖片需要自己找...
    /*點(diǎn)擊欄*/
    .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中調(diào)用DAO層的方法,給currentPage和pageSize設(shè)置初始值,然后就返回一個(gè)list到你分頁(yè)的頁(yè)面迭代,以后就直接嵌套在分頁(yè)頁(yè)面中就行

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


    只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。


    網(wǎng)站導(dǎo)航:
     
    主站蜘蛛池模板: 四虎成年永久免费网站| 卡1卡2卡3卡4卡5免费视频| 日本xxxx色视频在线观看免费| 国产a视频精品免费观看| 亚洲高清在线视频| 国产亚洲色婷婷久久99精品| 亚洲精品网站在线观看你懂的| 最好2018中文免费视频| 中文字幕免费在线看线人| 亚洲综合无码一区二区| 男女交性无遮挡免费视频| 免费人成在线观看网站视频| 亚洲成无码人在线观看| a毛片免费全部在线播放**| 中文字幕视频免费| 国产精品亚洲精品日韩已方| 亚洲五月丁香综合视频| 日本一区午夜艳熟免费| 亚洲情XO亚洲色XO无码| 免费大片黄在线观看| 久久久久无码专区亚洲av| 久久久久亚洲精品无码网址色欲| xxxxwww免费| 亚洲综合一区无码精品| 精品无码国产污污污免费网站 | 国产亚洲人成A在线V网站| 国产精品无码免费专区午夜| 午夜视频在线观看免费完整版| 国产精品久久久久久亚洲影视| 又粗又大又黑又长的免费视频| 国产精品亚洲а∨无码播放| 亚洲精品国产免费| 久久亚洲AV无码精品色午夜 | 99re6热视频精品免费观看| 亚洲国产美女精品久久| 国产一级淫片免费播放电影| 中文字幕乱码亚洲精品一区| 亚色九九九全国免费视频| 国产99久久亚洲综合精品| 国产精品无码一区二区三区免费 | 亚洲人成网站在线播放vr|