一区二区三区在线-一区二区三区亚洲视频-一区二区三区亚洲-一区二区三区午夜-一区二区三区四区在线视频-一区二区三区四区在线免费观看

服務器之家:專注于服務器技術及軟件下載分享
分類導航

PHP教程|ASP.NET教程|Java教程|ASP教程|編程技術|正則表達式|C/C++|IOS|C#|Swift|Android|VB|R語言|JavaScript|易語言|vb.net|

服務器之家 - 編程語言 - Java教程 - Java實現分頁的前臺頁面和后臺代碼

Java實現分頁的前臺頁面和后臺代碼

2020-08-29 14:50dKnightL Java教程

這篇文章主要為大家詳細介紹了Java實現分頁的前臺頁面和后臺代碼,具有一定的參考價值,感興趣的小伙伴們可以參考一下

本文實例為大家分享了Java分頁展示的具體代碼,供大家參考,具體內容如下

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

Java實現分頁的前臺頁面和后臺代碼

前臺JSP頁面

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
<%@ 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>數據交易貓</title>
 <script type="text/javascript">
 
 //1分頁下,動態添加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(){
 
 })
 //根據頁數查詢數據列表
 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("失敗");
   },
   });
 }
 
 //根據下拉查詢數據列表
 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("失敗");
   },
   });
  }
 //根據下拉選擇排序方式
 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>
 
    <!-- 內容-->
    <div class="well">
    <!-- 標題-->
     <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">價格降序</option>
          <input id="backSortValue" type="hidden" value="${sortValue}">
         </select>
         <hr class="mrgZero mrgTopSma"/>
       </div>
      </div>
     </div>    
    <!-- 內容-->
      <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">
 
        <!-- 判斷當前頁是否位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>
 
       <!-- 判斷當前頁和總頁數,小于則顯示下一頁, -->
       <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">跳轉到第&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

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
//查詢需求列表
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"); //當前頁碼條件
  session.put("sessionReqSortValue","publishDatetime");
 }else{
 hql=hql+"order by r."+sortValue+" desc";
  ActionContext.getContext().put("sortValue", sortValue); //當前頁碼條件
  session.put("sessionReqSortValue",sortValue);
 }
 long icount=requirementService.countAllRe();//總記錄數
 long allPage;//總頁數
 //判斷是否能整除,能則直接,不能則+1;
 if((icount%pageSize)==0){
  allPage=icount/pageSize;
 }
 else{
  allPage=(icount/pageSize)+1;
 }
 System.out.println("總記錄:"+icount+";總頁數:"+allPage+";當前頁碼:"+pageNo);
 List<Requirement> requiList=requirementService.queryByPage(hql, pageNo, pageSize);
 ActionContext.getContext().put("requiList", requiList);//需求列表
 ActionContext.getContext().put("icount", icount);//總記錄數
 ActionContext.getContext().put("allPage", allPage);//總頁數
 ActionContext.getContext().put("currentPage", pageNo); //當前頁碼
 session.put("sessionCurrentPage", pageNo);
 return "requireContent";
 
}

service

?
1
2
3
4
5
6
public long countAllRe() {
 return requirementDao.countAllRe();
}
 public List<T> queryByPage(String hql, int pageNo, int pageSize) {
 return requirementDao.queryByPage(hql, pageNo, pageSize);
}

dao

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
//這里可能會報錯,就是直接查詢數據列表(使用了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();
}

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持服務器之家。

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 日本人黄色 | 美女免费观看一区二区三区 | cos美女被黄网站 | 精品国产乱码久久久久久免费 | 国产成人盗拍精品免费视频 | 日韩亚洲欧美综合一区二区三区 | 深夜精品高中女学生 | 免费看又黄又爽又猛的视频软件- | 爽爽窝窝午夜精品一区二区 | 午夜电影三级还珠格格 | 亚洲女bbwxxxx另类 | 色女阁 | 99国产情在线视频 | 亚洲邪恶天堂影院在线观看 | 娇喘高潮教室h | 女上男下gifxxoo动态视频 | 日韩一级片在线播放 | 学校捏奶揉下面污文h | 日本天堂视频在线观看 | 日本成人黄色网址 | 久久精品99国产精品日本 | 我在厨房摸岳的乳HD在线观看 | 免费操比视频 | 色8| 成人国产精品一级毛片视频 | 男人的天堂在线观看入口 | voyeur 中国女厕 亚洲女厕 | www伊人| 免费观看在线永久免费xx视频 | 蜜桃视频一区二区 | 亚洲图片综合区 | 好紧水好多 | 亚洲老头老太hd | 乖女的嫩奶水h文孕妇 | 免费视频专区一国产盗摄 | 小寡妇好紧进去了好大看视频 | 2021最新国产成人精品视频 | 369看片网| chaopeng在线观看| 青青草一区二区免费精品 | 奇米狠狠色|