当前位置: 移动技术网 > IT编程>开发语言>Java > javaweb分页

javaweb分页

2018年12月01日  | 移动技术网IT编程  | 我要评论
 1 package com.aishang.util;
 2 //分页
 3 public class pagemethod {
 4     public static int[] getpagearray(int selindex, int pagecount) {
 5         int str [] = null;
 6         if(pagecount<5){
 7             str = new int [pagecount] ;
 8 
 9             for(int x = 1 ;x <= pagecount;x ++){
10                 str[x-1] = x ;
11             }
12         }else{
13             if(selindex<=2){
14                 int y = 0 ;
15                 str = new int [5];
16                 for(int x = 1 ;x <= 5;x ++){
17                     str[y] = x ;
18                     y++;
19 
20                 }
21             }else if(selindex>=3&&selindex+2<=pagecount){
22                 int y = 0 ;
23                 str = new int [5];
24                 for(int x = (selindex-2); x < (selindex+3);x ++){
25                     str[y] = x ;
26                     y ++;
27 
28                 }
29             }else{
30                 str = new int [5];
31                 int y = 0 ;
32                 for(int x = pagecount-4;x <=pagecount; x ++){
33                     str[y] = x ;
34                     y++;
35                 }
36             }
37         }
38         return str;
39     }
40 
41 }
42 controller层:
43 
44 pagemethod pg = new pagemethod();
45 
46 request.setattribute("pg", pg.getpagearray(pagenow, pagecount));
47 
48 页面:
49 
50 <div style=" margin: 0 0 0px 50px;padding:0 0 20px 0; width: 70%;">
51                                 <c:if test="${pagenow!=1 && pagecount>1}">
52                                         <a href="<c:url value="/admin/newscontroller?flan=newslist&pagenow=1&typeid=${typeid}&selpend=${selpend}&selnewsname=${selnewsname}"/>"> 【首页】 </a>
53                                         <a href="<c:url value="/admin/newscontroller?flan=newslist&pagenow=${pagenow-1}&typeid=${typeid}&selpend=${selpend}&selnewsname=${selnewsname}"/>"> 【上一页】 </a>
54                                     </c:if>
55                                     <c:foreach items="${pg}" var="pg">
56                                             <a href="/aishang/admin/newscontroller?flan=newslist&pagenow=${pg}&typeid=${typeid}&selpend=${selpend}&selnewsname=${selnewsname}"> 【${pg}】</a>
57                                     </c:foreach>
58                                     <c:if test="${pagenow!=pagecount && pagecount>1}">
59                                         <a href="<c:url value="/admin/newscontroller?flan=newslist&pagenow=${pagenow+1}&typeid=${typeid}&selpend=${selpend}&selnewsname=${selnewsname}"/>"> 【下一页】 </a>
60                                         <a href="<c:url value="/admin/newscontroller?flan=newslist&pagenow=${pagecount}&typeid=${typeid}&selpend=${selpend}&selnewsname=${selnewsname}"/>"> 【末页】 </a>
61                                         
62                                     </c:if>
63                                     </div>

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网