最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Java實(shí)現(xiàn)分頁的前臺(tái)頁面和后臺(tái)代碼

 更新時(shí)間:2017年03月17日 08:20:39   作者:dKnightL  
這篇文章主要為大家詳細(xì)介紹了Java實(shí)現(xiàn)分頁的前臺(tái)頁面和后臺(tái)代碼,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了Java分頁展示的具體代碼,供大家參考,具體內(nèi)容如下

先上圖吧,大致如圖,也就提供個(gè)思路(ps:使用了SSH框架)

前臺(tái)JSP頁面

<%@ page language="java" contentType="text/html; charset=utf-8"
 pageEncoding="utf-8"%>
<%@taglib prefix="s" uri="/struts-tags"%>  
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
 <title>數(shù)據(jù)交易貓</title> 
 <script type="text/javascript"> 

 //1分頁下,動(dòng)態(tài)添加disable給分頁按鈕
 /*
 $(function(){
  var myPageId="#"+$("#hidCurrentPage").val();
  var myPageAId="#"+$("#hidCurrentPage").val()+" a";
  $(myPageAId).addClass('main-bgcolor');
  $(myPageAId).attr('href','javascript:void(0)')
  $(myPageId).addClass('disabled');
  $(myPageId).addClass('disabledControl');

 })
 */
 //
 $(function(){

 })
 //根據(jù)頁數(shù)查詢數(shù)據(jù)列表
 function queryRequirListByPage(i) {
  var pageNo=i;
  var sortValue=$('#hidSortValue').val();
  $.ajax({
   url:'${pageContext.request.contextPath}/bid/reAction_queryRequirListByPage.action',
   type:'POST',
   data:{
    sortValue:sortValue,
    pageNo:pageNo
   },
   success:function(datas){ 
    $('#requireContentDiv').html(datas);          
   },
   error:function(){
    alert("失敗");
   },
   });
 }

 //根據(jù)下拉查詢數(shù)據(jù)列表
 function selectPage(obj){
  var pageNo=obj.options[obj.selectedIndex].value;
  var sortValue=$('#hidSortValue').val();
  $.ajax({
   url:'${pageContext.request.contextPath}/bid/reAction_queryRequirListByPage.action',
   type:'POST',
   data:{
    sortValue:sortValue,
    pageNo:pageNo
   },
   success:function(datas){ 
    $('#requireContentDiv').html(datas);          
   },
   error:function(){
    alert("失敗");
   },
   });
  }
 //根據(jù)下拉選擇排序方式
 function selectSort(obj){
  var sortValue = obj.options[obj.selectedIndex].value;
  var pageNo =1;
  $.ajax({
   url:'${pageContext.request.contextPath}/bid/reAction_queryRequirListByPage.action',
   type:'POST',
   data:{sortValue:sortValue,
     pageNo:pageNo
    },
   success:function(datas){ 
    $('#requireContentDiv').html(datas);


   },
   error:function(){
    alert("失敗");
   },
   });
  }

  $(document).ready(function(){
   var backSortValue=$('#backSortValue').val();
   console.log("backSortValue"+backSortValue)
   $("#category option").each(function(){
    var thisId='#'+this.id;
    var thisValue=this.value;
    if(backSortValue==thisValue){
     $(thisId).attr('selected','selected');
    }
   });
  })
 </script> 
</head>
<body>

    <!-- 內(nèi)容-->
    <div class="well">
    <!-- 標(biāo)題-->
     <div class="box"><h3><span class="glyphicon glyphicon-list" ></span>需求列表</h3></div>
    <!-- 篩選條件--> 
     <div class="box">
      <div class="row">
       <div class="col-xs-12">        
         <span>篩選:按</span>
         <select id="category" name="category" onchange="selectSort(this)">
          <option id="categoryTime" value="publishDatetime">最新</option>
          <option id="categoryPrice" value="price">價(jià)格降序</option>
          <input id="backSortValue" type="hidden" value="${sortValue}">
         </select>
         <hr class="mrgZero mrgTopSma"/>
       </div>
      </div>
     </div>     
    <!-- 內(nèi)容-->
      <input type="hidden" name="hidCurrentPage2" id="hidCurrentPage" value="${currentPage}">
      <input type="hidden" id="hidAllPage" value="${allPage}">
      <input type="hidden" id="hidSortValue" value="${sortValue}">
      <s:iterator value="#requiList">

      <div class="data-down-box">
       <div class="row">
        <div class="col-xs-12">
         <h4 class="ellipsis"><a href="${pageContext.request.contextPath}/bid/bidAction_queryById?id=${id}" rel="external nofollow" onclick="reward()">${title}</a></h4>
        </div>                         
       </div>
       <div class="row mrgTopSma">
        <div class="col-xs-12 ">      
         <p class="data-provider padLeftBig sec-color ellipsis">懸賞積分:<span>${price}</span></p>
         <p class="data-intro padLeftBig ellipsis sec-color">需求描述:<span>${requirementDescription}</span></p>
        </div>    
       </div>
       <hr/>  
      </div>

      </s:iterator>
     <!-- 分頁 -->
     <div id="rePagerDiv" class="rePagerDiv box">
      <nav>
       <ul class="pager">

        <!-- 判斷當(dāng)前頁是否位1,如果不為1則顯示上一頁, --> 
        <s:if test="1 == #currentPage">  
        </s:if>
        <s:else>
        <li>  
         <a href="javascript:void(0)" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" aria-label="Previous" onclick="queryRequirListByPage(${currentPage-1})">
         <span aria-hidden="true">&laquo;</span>
         </a>
        </li>  
        </s:else>

       <!-- 首頁 -->        
       <li><a href="javascript:void(0)" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" onclick="queryRequirListByPage(1)">首頁</a></li>

       <li>
        <span><span class="main-color">${currentPage}</span>/&nbsp;${allPage}頁</span>        
       </li>

       <!-- 尾頁 -->        
       <li><a href="javascript:void(0)" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" onclick="queryRequirListByPage(${allPage})">尾頁</a></li>

       <!-- 判斷當(dāng)前頁和總頁數(shù),小于則顯示下一頁, --> 
       <s:if test="#currentPage < #allPage">
        <li>
         <a href="javascript:void(0)" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" aria-label="Next" onclick="queryRequirListByPage(${currentPage+1})">
         <span aria-hidden="true">&raquo;</span>
         </a>
        </li>
       </s:if>
       <li>
        <span class="skipPageSpan">跳轉(zhuǎn)到第&nbsp;
        <select onchange="selectPage(this)">
         <s:iterator var="lst" begin="1" end="#allPage" step="1">          
          <s:if test="%{#lst == #currentPage}">
           <option selected="selected" value="<s:property/>" ><s:property/></option>  
           </s:if>
           <s:else>
            <option value="<s:property/>" ><s:property/></option>
           </s:else>
         </s:iterator>                    
        </select>
        &nbsp;頁
        </span>
        </li>

       </ul>
      </nav>

     </div>      


     </div>     




 <hr/>

</body>
</html>

action

 //查詢需求列表
 public String queryRequirListByPage(){
  int pageSize=5;//每頁記錄
  String hql="select r from Requirement r where r.reStatus !=2 ";
  if(sortValue == null || sortValue.length() <= 0){
   hql=hql+"order by r.publishDatetime desc";
   ActionContext.getContext().put("sortValue", "publishDatetime"); //當(dāng)前頁碼條件
   session.put("sessionReqSortValue","publishDatetime");
  }else{
  hql=hql+"order by r."+sortValue+" desc";
   ActionContext.getContext().put("sortValue", sortValue); //當(dāng)前頁碼條件
   session.put("sessionReqSortValue",sortValue);
  }
  long icount=requirementService.countAllRe();//總記錄數(shù)
  long allPage;//總頁數(shù)
  //判斷是否能整除,能則直接,不能則+1;
  if((icount%pageSize)==0){
   allPage=icount/pageSize;
  }
  else{
   allPage=(icount/pageSize)+1;
  }
  System.out.println("總記錄:"+icount+";總頁數(shù):"+allPage+";當(dāng)前頁碼:"+pageNo);
  List<Requirement> requiList=requirementService.queryByPage(hql, pageNo, pageSize);
  ActionContext.getContext().put("requiList", requiList);//需求列表
  ActionContext.getContext().put("icount", icount);//總記錄數(shù)
  ActionContext.getContext().put("allPage", allPage);//總頁數(shù)
  ActionContext.getContext().put("currentPage", pageNo); //當(dāng)前頁碼
  session.put("sessionCurrentPage", pageNo);
  return "requireContent";

 }

service

  public long countAllRe() {
  return requirementDao.countAllRe();
 }
  public List<T> queryByPage(String hql, int pageNo, int pageSize) {
  return requirementDao.queryByPage(hql, pageNo, pageSize);
 }

dao

 //這里可能會(huì)報(bào)錯(cuò),就是直接查詢數(shù)據(jù)列表(使用了SSH)
 public long countAll() {
  List<?> l = getSession().createQuery("select count(*) from "
    + clazz.getSimpleName()).list();
  if (l != null && l.size() == 1 )
  {
   return (Long)l.get(0);
  }
  return 0;
 }
 public List<T> queryByPage(String hql, int pageNo, int pageSize) {
  return getSession()
    .createQuery(hql)
    .setFirstResult((pageNo - 1) * pageSize)
    .setMaxResults(pageSize)
    .list();
 }

以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • Apache Maven創(chuàng)建工程的實(shí)現(xiàn)示例

    Apache Maven創(chuàng)建工程的實(shí)現(xiàn)示例

    本文詳細(xì)介紹了如何使用Maven創(chuàng)建一個(gè)新的Java工程,包括使用maven-archetype-plugin插件、項(xiàng)目的基本結(jié)構(gòu)和文件、構(gòu)建和運(yùn)行項(xiàng)目的方法以及常見問題的解決,Maven通過簡化項(xiàng)目構(gòu)建和依賴管理,成為Java開發(fā)中不可或缺的工具
    2024-11-11
  • Maven指定JDK版本的實(shí)現(xiàn)

    Maven指定JDK版本的實(shí)現(xiàn)

    本文主要介紹了Maven指定JDK版本的實(shí)現(xiàn),主要有兩種方式,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2023-09-09
  • java中幾種常見的排序算法總結(jié)

    java中幾種常見的排序算法總結(jié)

    大家好,本篇文章主要講的是java中幾種常見的排序算法總結(jié),感興趣的同學(xué)趕快來看一看吧,對(duì)你有幫助的話記得收藏一下
    2022-01-01
  • Java實(shí)戰(zhàn)入門之雙色球彩票小游戲

    Java實(shí)戰(zhàn)入門之雙色球彩票小游戲

    這篇文章主要介紹了Java實(shí)戰(zhàn)入門之雙色球彩票,文中有非常詳細(xì)的代碼示例,對(duì)正在學(xué)習(xí)java的小伙伴們有非常好的幫助,需要的朋友可以參考下
    2021-04-04
  • java查找文件夾下最新生成的文件的方法

    java查找文件夾下最新生成的文件的方法

    在本篇文章中我們給大家分享了關(guān)于java怎么查找文件夾下最新生成的文件的相關(guān)方法和知識(shí)點(diǎn),有需要的朋友們參考下。
    2019-07-07
  • Java特性隊(duì)列和棧的堵塞原理解析

    Java特性隊(duì)列和棧的堵塞原理解析

    這篇文章主要介紹了Java特性隊(duì)列和棧的堵塞原理解析,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2020-10-10
  • java持久層框架mybatis防止sql注入的方法

    java持久層框架mybatis防止sql注入的方法

    下面小編就為大家?guī)硪黄猨ava持久層框架mybatis防止sql注入的方法。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2016-10-10
  • MyBatis動(dòng)態(tài)創(chuàng)建表的實(shí)例代碼

    MyBatis動(dòng)態(tài)創(chuàng)建表的實(shí)例代碼

    在項(xiàng)目需求中,我們經(jīng)常會(huì)遇到動(dòng)態(tài)操作數(shù)據(jù)表的需求,常見的我們會(huì)把日志、設(shè)備實(shí)時(shí)位置信息等存入數(shù)據(jù)表,并且以一定時(shí)間段生成一個(gè)表來存儲(chǔ)。接下來通過本文給大家介紹MyBatis動(dòng)態(tài)創(chuàng)建表的方法,感興趣的朋友一起看看吧
    2018-07-07
  • mybatis-plus?插入修改配置默認(rèn)值的實(shí)現(xiàn)方式

    mybatis-plus?插入修改配置默認(rèn)值的實(shí)現(xiàn)方式

    這篇文章主要介紹了mybatis-plus?插入修改配置默認(rèn)值的實(shí)現(xiàn)方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2022-07-07
  • Java中File文件操作類的基礎(chǔ)用法

    Java中File文件操作類的基礎(chǔ)用法

    這篇文章主要給大家介紹了關(guān)于Java中File文件操作類基礎(chǔ)用法的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家學(xué)習(xí)或者使用File類具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2018-07-07

最新評(píng)論

霍州市| 法库县| 柳州市| 定州市| 商水县| 新余市| 惠水县| 天门市| 福海县| 武汉市| 邢台市| 花莲县| 眉山市| 茶陵县| 镇沅| 江油市| 四平市| 铜梁县| 全南县| 临西县| 镇平县| 凉城县| 壶关县| 启东市| 万全县| 通辽市| 武城县| 波密县| 信丰县| 瑞金市| 通海县| 奉新县| 涞源县| 自贡市| 阳江市| 泰和县| 沙坪坝区| 谷城县| 县级市| 左权县| 古浪县|