初始時頁面的效果,其頁面的數據都是寫固定的:javascript
其html代碼:css
1 <!DOCTYPE html> 2 <html> 3 4 <head> 5 <meta charset="UTF-8"> 6 <title>泉師釋疑</title> 7 <meta name="renderer" content="webkit"> 8 <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> 9 <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" /> 10 <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" /> 11 <link rel="stylesheet" href="./css/font.css"> 12 <link rel="stylesheet" href="./css/xadmin.css"> 13 <script type="text/javascript" src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script> 14 <script type="text/javascript" src="./lib/layui/layui.js" charset="utf-8"></script> 15 <script type="text/javascript" src="./js/xadmin.js"></script> 16 <!-- 讓IE8/9支持媒體查詢,從而兼容柵格 --> 17 <!--[if lt IE 9]> 18 <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script> 19 <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script> 20 <![endif]--> 21 </head> 22 23 <body class="layui-anim layui-anim-up"> 24 <div class="x-nav"> 25 <span class="layui-breadcrumb"> 26 <a href="">首頁</a> 27 <a href="">演示</a> 28 <a> 29 <cite>導航元素</cite></a> 30 </span> 31 <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" href="javascript:location.replace(location.href);" title="刷新"> 32 <i class="layui-icon" style="line-height:30px">ဂ</i></a> 33 </div> 34 <div class="x-body"> 35 <div class="layui-row"> 36 <form class="layui-form layui-col-md12 x-so"> 37 <input class="layui-input" placeholder="開始日" name="start" id="start"> 38 <input class="layui-input" placeholder="截止日" name="end" id="end"> 39 <input type="text" name="username" placeholder="請輸入用戶名" autocomplete="off" class="layui-input"> 40 <button class="layui-btn" lay-submit="" lay-filter="sreach"><i class="layui-icon"></i></button> 41 </form> 42 </div> 43 <xblock> 44 <button class="layui-btn layui-btn-danger" onclick="delAll()"><i class="layui-icon"></i>批量刪除</button> 45 <button class="layui-btn" onclick="x_admin_show('添加用戶','./member-add.html',600,400)"><i class="layui-icon"></i>添加</button> 46 <span class="x-right" style="line-height:40px">共有數據:88 條</span> 47 </xblock> 48 <table class="layui-table"> 49 <thead> 50 <tr> 51 <th> 52 <div class="layui-unselect header layui-form-checkbox" lay-skin="primary"><i class="layui-icon"></i></div> 53 </th> 54 <th>ID</th> 55 <th>用戶名</th> 56 <th>性別</th> 57 <th>手機</th> 58 <th>郵箱</th> 59 <th>地址</th> 60 <th>加入時間</th> 61 <th>狀態</th> 62 <th>操做</th></tr> 63 </thead> 64 <tbody> 65 <tr> 66 <td> 67 <div class="layui-unselect layui-form-checkbox" lay-skin="primary" data-id='2'><i class="layui-icon"></i></div> 68 </td> 69 <td>1</td> 70 <td>小明</td> 71 <td>男</td> 72 <td>13000000000</td> 73 <td>admin@mail.com</td> 74 <td>北京市 海淀區</td> 75 <td>2017-01-01 11:11:42</td> 76 <td class="td-status"> 77 <span class="layui-btn layui-btn-normal layui-btn-mini">已啓用</span></td> 78 <td class="td-manage"> 79 <a onclick="member_stop(this,'10001')" href="javascript:;" title="啓用"> 80 <i class="layui-icon"></i> 81 </a> 82 <a title="編輯" onclick="x_admin_show('編輯','member-edit.html',600,400)" href="javascript:;"> 83 <i class="layui-icon"></i> 84 </a> 85 <a onclick="x_admin_show('修改密碼','member-password.html',600,400)" title="修改密碼" href="javascript:;"> 86 <i class="layui-icon"></i> 87 </a> 88 <a title="刪除" onclick="member_del(this,'要刪除的id')" href="javascript:;"> 89 <i class="layui-icon"></i> 90 </a> 91 </td> 92 </tr> 93 <tr> 94 <td> 95 <div class="layui-unselect layui-form-checkbox" lay-skin="primary" data-id='2'><i class="layui-icon"></i></div> 96 </td> 97 <td>1</td> 98 <td>小明</td> 99 <td>男</td> 100 <td>13000000000</td> 101 <td>admin@mail.com</td> 102 <td>北京市 海淀區</td> 103 <td>2017-01-01 11:11:42</td> 104 <td class="td-status"> 105 <span class="layui-btn layui-btn-normal layui-btn-mini">已啓用</span></td> 106 <td class="td-manage"> 107 <a onclick="member_stop(this,'10001')" href="javascript:;" title="啓用"> 108 <i class="layui-icon"></i> 109 </a> 110 <a title="編輯" onclick="x_admin_show('編輯','member-edit.html',600,400)" href="javascript:;"> 111 <i class="layui-icon"></i> 112 </a> 113 <a onclick="x_admin_show('修改密碼','member-password.html',600,400)" title="修改密碼" href="javascript:;"> 114 <i class="layui-icon"></i> 115 </a> 116 <a title="刪除" onclick="member_del(this,'要刪除的id')" href="javascript:;"> 117 <i class="layui-icon"></i> 118 </a> 119 </td> 120 </tr> 121 </tbody> 122 </table> 123 <div class="page"> 124 <div> 125 <a class="prev" href=""><<</a> 126 <a class="num" href="">1</a> 127 <span class="current">2</span> 128 <a class="num" href="">3</a> 129 <a class="num" href="">489</a> 130 <a class="next" href="">>></a> 131 </div> 132 </div> 133 134 </div> 135 <script> 136 layui.use('laydate', function(){ 137 var laydate = layui.laydate; 138 139 //執行一個laydate實例 140 laydate.render({ 141 elem: '#start' //指定元素 142 }); 143 144 //執行一個laydate實例 145 laydate.render({ 146 elem: '#end' //指定元素 147 }); 148 }); 149 150 /*用戶-停用*/ 151 function member_stop(obj,id){ 152 layer.confirm('確認要停用嗎?',function(index){ 153 154 if($(obj).attr('title')=='啓用'){ 155 156 //發異步把用戶狀態進行更改 157 $(obj).attr('title','停用') 158 $(obj).find('i').html(''); 159 160 $(obj).parents("tr").find(".td-status").find('span').addClass('layui-btn-disabled').html('已停用'); 161 layer.msg('已停用!',{icon: 5,time:1000}); 162 163 }else{ 164 $(obj).attr('title','啓用') 165 $(obj).find('i').html(''); 166 167 $(obj).parents("tr").find(".td-status").find('span').removeClass('layui-btn-disabled').html('已啓用'); 168 layer.msg('已啓用!',{icon: 5,time:1000}); 169 } 170 171 }); 172 } 173 174 /*用戶-刪除*/ 175 function member_del(obj,id){ 176 layer.confirm('確認要刪除嗎?',function(index){ 177 //發異步刪除數據 178 $(obj).parents("tr").remove(); 179 layer.msg('已刪除!',{icon:1,time:1000}); 180 }); 181 } 182 183 184 185 function delAll (argument) { 186 187 var data = tableCheck.getData(); 188 189 layer.confirm('確認要刪除嗎?'+data,function(index){ 190 //捉到全部被選中的,發異步進行刪除 191 layer.msg('刪除成功', {icon: 1}); 192 $(".layui-form-checked").not('.header').parents('tr').remove(); 193 }); 194 } 195 </script> 196 <script>var _hmt = _hmt || []; (function() { 197 var hm = document.createElement("script"); 198 hm.src = "https://hm.baidu.com/hm.js?b393d153aeb26b46e9431fabaf0f6190"; 199 var s = document.getElementsByTagName("script")[0]; 200 s.parentNode.insertBefore(hm, s); 201 })();</script> 202 </body> 203 204 </html>
將html代碼轉換爲jsp改成user_list.jsphtml
1 <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> 2 <%@ taglib uri="/struts-tags" prefix="s"%> 3 4 <!DOCTYPE html> 5 <html> 6 7 <head> 8 <meta charset="UTF-8"> 9 <title>泉師釋疑</title> 10 <meta name="renderer" content="webkit"> 11 <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> 12 <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" /> 13 <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" /> 14 <link rel="stylesheet" href="./css/font.css"> 15 <link rel="stylesheet" href="./css/xadmin.css"> 16 <script type="text/javascript" src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script> 17 <script type="text/javascript" src="./lib/layui/layui.js" charset="utf-8"></script> 18 <script type="text/javascript" src="./js/xadmin.js"></script> 19 <!-- 讓IE8/9支持媒體查詢,從而兼容柵格 --> 20 <!--[if lt IE 9]> 21 <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script> 22 <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script> 23 <![endif]--> 24 </head> 25 26 <body class="layui-anim layui-anim-up"> 27 <div class="x-nav"> 28 <span class="layui-breadcrumb"> 29 <a href="">首頁</a> 30 <a href="">演示</a> 31 <a> 32 <cite>導航元素</cite></a> 33 </span> 34 <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" href="javascript:location.replace(location.href);" title="刷新"> 35 <i class="layui-icon" style="line-height:30px">ဂ</i></a> 36 </div> 37 <div class="x-body"> 38 <div class="layui-row"> 39 <form class="layui-form layui-col-md12 x-so"> 40 <input class="layui-input" placeholder="開始日" name="start" id="start"> 41 <input class="layui-input" placeholder="截止日" name="end" id="end"> 42 <input type="text" name="username" placeholder="請輸入用戶名" autocomplete="off" class="layui-input"> 43 <button class="layui-btn" lay-submit="" lay-filter="sreach"><i class="layui-icon"></i></button> 44 </form> 45 </div> 46 <xblock> 47 <button class="layui-btn layui-btn-danger" onclick="delAll()"><i class="layui-icon"></i>批量刪除</button> 48 <button class="layui-btn" onclick="x_admin_show('添加用戶','./member-add.html',600,400)"><i class="layui-icon"></i>添加</button> 49 <span class="x-right" style="line-height:40px">共有數據:88 條</span> 50 </xblock> 51 <table class="layui-table"> 52 <thead> 53 <tr> 54 <th> 55 <div class="layui-unselect header layui-form-checkbox" lay-skin="primary"><i class="layui-icon"></i></div> 56 </th> 57 <th>ID</th> 58 <th>用戶名</th> 59 <th>性別</th> 60 <th>手機</th> 61 <th>郵箱</th> 62 <th>地址</th> 63 <th>加入時間</th> 64 <th>狀態</th> 65 <th>操做</th></tr> 66 </thead> 67 <tbody> 68 <tr> 69 <td> 70 <div class="layui-unselect layui-form-checkbox" lay-skin="primary" data-id='2'><i class="layui-icon"></i></div> 71 </td> 72 <td>1</td> 73 <td>小明</td> 74 <td>男</td> 75 <td>13000000000</td> 76 <td>admin@mail.com</td> 77 <td>北京市 海淀區</td> 78 <td>2017-01-01 11:11:42</td> 79 <td class="td-status"> 80 <span class="layui-btn layui-btn-normal layui-btn-mini">已啓用</span></td> 81 <td class="td-manage"> 82 <a onclick="member_stop(this,'10001')" href="javascript:;" title="啓用"> 83 <i class="layui-icon"></i> 84 </a> 85 <a title="編輯" onclick="x_admin_show('編輯','member-edit.html',600,400)" href="javascript:;"> 86 <i class="layui-icon"></i> 87 </a> 88 <a onclick="x_admin_show('修改密碼','member-password.html',600,400)" title="修改密碼" href="javascript:;"> 89 <i class="layui-icon"></i> 90 </a> 91 <a title="刪除" onclick="member_del(this,'要刪除的id')" href="javascript:;"> 92 <i class="layui-icon"></i> 93 </a> 94 </td> 95 </tr> 96 <tr> 97 <td> 98 <div class="layui-unselect layui-form-checkbox" lay-skin="primary" data-id='2'><i class="layui-icon"></i></div> 99 </td> 100 <td>1</td> 101 <td>小明</td> 102 <td>男</td> 103 <td>13000000000</td> 104 <td>admin@mail.com</td> 105 <td>北京市 海淀區</td> 106 <td>2017-01-01 11:11:42</td> 107 <td class="td-status"> 108 <span class="layui-btn layui-btn-normal layui-btn-mini">已啓用</span></td> 109 <td class="td-manage"> 110 <a onclick="member_stop(this,'10001')" href="javascript:;" title="啓用"> 111 <i class="layui-icon"></i> 112 </a> 113 <a title="編輯" onclick="x_admin_show('編輯','member-edit.html',600,400)" href="javascript:;"> 114 <i class="layui-icon"></i> 115 </a> 116 <a onclick="x_admin_show('修改密碼','member-password.html',600,400)" title="修改密碼" href="javascript:;"> 117 <i class="layui-icon"></i> 118 </a> 119 <a title="刪除" onclick="member_del(this,'要刪除的id')" href="javascript:;"> 120 <i class="layui-icon"></i> 121 </a> 122 </td> 123 </tr> 124 </tbody> 125 </table> 126 <div class="page"> 127 <div> 128 <a class="prev" href=""><<</a> 129 <a class="num" href="">1</a> 130 <span class="current">2</span> 131 <a class="num" href="">3</a> 132 <a class="num" href="">489</a> 133 <a class="next" href="">>></a> 134 </div> 135 </div> 136 137 </div> 138 <script> 139 layui.use('laydate', function(){ 140 var laydate = layui.laydate; 141 142 //執行一個laydate實例 143 laydate.render({ 144 elem: '#start' //指定元素 145 }); 146 147 //執行一個laydate實例 148 laydate.render({ 149 elem: '#end' //指定元素 150 }); 151 }); 152 153 /*用戶-停用*/ 154 function member_stop(obj,id){ 155 layer.confirm('確認要停用嗎?',function(index){ 156 157 if($(obj).attr('title')=='啓用'){ 158 159 //發異步把用戶狀態進行更改 160 $(obj).attr('title','停用') 161 $(obj).find('i').html(''); 162 163 $(obj).parents("tr").find(".td-status").find('span').addClass('layui-btn-disabled').html('已停用'); 164 layer.msg('已停用!',{icon: 5,time:1000}); 165 166 }else{ 167 $(obj).attr('title','啓用') 168 $(obj).find('i').html(''); 169 170 $(obj).parents("tr").find(".td-status").find('span').removeClass('layui-btn-disabled').html('已啓用'); 171 layer.msg('已啓用!',{icon: 5,time:1000}); 172 } 173 174 }); 175 } 176 177 /*用戶-刪除*/ 178 function member_del(obj,id){ 179 layer.confirm('確認要刪除嗎?',function(index){ 180 //發異步刪除數據 181 $(obj).parents("tr").remove(); 182 layer.msg('已刪除!',{icon:1,time:1000}); 183 }); 184 } 185 186 187 188 function delAll (argument) { 189 190 var data = tableCheck.getData(); 191 192 layer.confirm('確認要刪除嗎?'+data,function(index){ 193 //捉到全部被選中的,發異步進行刪除 194 layer.msg('刪除成功', {icon: 1}); 195 $(".layui-form-checked").not('.header').parents('tr').remove(); 196 }); 197 } 198 </script> 199 <script>var _hmt = _hmt || []; (function() { 200 var hm = document.createElement("script"); 201 hm.src = "https://hm.baidu.com/hm.js?b393d153aeb26b46e9431fabaf0f6190"; 202 var s = document.getElementsByTagName("script")[0]; 203 s.parentNode.insertBefore(hm, s); 204 })();</script> 205 </body> 206 207 </html>
並在index.jsp中將用戶列表的a標籤中的連接改成:前端
<a _href="${pageContext.request.contextPath }/UserAction_getAllUser"> <i class="iconfont"></i> <cite>用戶列表</cite> </a>
在web層建立一個類UserAction.java在其中建立一個方getAllUserhtml5
//獲取用戶列表 public String getAllUser() throws Exception { return "userList"; }
將用戶列表的信息經過分頁的方法展現於頁面java
須要5個參數,經過起始頁與頁面大小能夠知道list,list能夠填充下圖:jquery
須要總頁數與總條數能夠填充頁面的共有的數據:web
分頁的顯示的總的分析:spring
在util層建立PagePean.java類sql
package com.guiyan.utils; import java.util.List; public class PageBean { private Integer currentPage;//起始頁 private Integer pageSize;//頁面大小 private Integer totalPage;//總頁數((總條數/頁面大小)向上取整) private Integer totalCount;//總條數 select count(*) private List list;//list public PageBean(Integer currentPage, Integer pageSize,Integer totalCount) { this.currentPage = currentPage; this.pageSize = pageSize; this.totalCount = totalCount; if(this.currentPage == null) { this.currentPage = 1; } if(this.pageSize == null) { this.pageSize = 5;//默認顯示5條 } if(this.currentPage > this.totalPage) { this.currentPage = this.totalPage; } if(this.currentPage < 1) { this.currentPage = 1; } //自動算出總頁數 ,進行向上取整 this.totalPage = (int) Math.ceil(1.0* this.totalCount / this.pageSize ); } public Integer getCurrentPage() { return currentPage; } public void setCurrentPage(Integer currentPage) { this.currentPage = currentPage; } public Integer getPageSize() { return pageSize; } public void setPageSize(Integer pageSize) { this.pageSize = pageSize; } public Integer getTotalPage() { return totalPage; } public void setTotalPage(Integer totalPage) { this.totalPage = totalPage; } public Integer getTotalCount() { return totalCount; } public void setTotalCount(Integer totalCount) { this.totalCount = totalCount; } public List getList() { return list; } public void setList(List list) { this.list = list; } }
須要進行訪問兩次數據庫
封裝PageBean,訪問service
在UserAction.java中的getAllUser()方法中寫入ActionContext.put
//獲得全部用戶 public String getAllUser() throws Exception { PageBean userPageBean = userService.getUserPageBean(); ActionContext.getContext().put("userPageBean", userPageBean); return "userList"; }
在service層中userService建立方法getUserPageBean
public PageBean getUserPageBean(null ) { Integer totalCount = userDao.getAllUser(); PageBean pageBean = new PageBean(null, 6, totalCount);//封裝的pageBean List<User> list = userDao.getPageBeanList(pageBean);
pageBean.setList(list);
return pageBean;
}
因爲起始索引與起始頁相差1,起始索引是從0開始,起始頁從1開始
所以在PageBean中寫入getStart方法:
public Integer getStart() { return (this.currentPage - 1)*this.pageSize; }
在dao層中的UserDao中寫入方法getPageBeanList
public List getPageBeanList(PageBean pageBean) { Session session = getHibernateTemplate().getSessionFactory().getCurrentSession(); String sql = "select * from user limit ?,?"; NativeQuery query = session.createSQLQuery(sql); query.addEntity(User.class); query.setParameter(1, pageBean.getStart());//起始索引,在PageBean.java封裝了該方法 query.setParameter(2, pageBean.getPageSize()); List list = query.list(); return list; }
配置struts.xml
<action name="UserAction_*" class="com.guiyan.web.UserAction" method="{1}"> <result name="userList">/user-list.jsp</result> </action>
配置spring進行注入:
<bean name="userAction" class="com.guiyan.web.UserAction" scope="prototype"> <property name="userService" ref="userService"></property> </bean>
進行前端代碼的書寫:
user_list.jsp
<table class="layui-table"> <thead> <tr> <th> <div class="layui-unselect header layui-form-checkbox" lay-skin="primary"> <i class="layui-icon"></i> </div> </th> <th>ID</th> <th>用戶名</th> <th>密碼</th> <th>真實姓名</th> <th>郵箱</th> <th>電話</th> <th>狀態</th> <th>等級</th> <th>操做</th> </tr> </thead> <tbody> <s:iterator value="#userPageBean.list" var="user" status="status"> <tr> <td> <div class="layui-unselect layui-form-checkbox" lay-skin="primary" data-id='2'> <i class="layui-icon"></i> <input type="hidden" name="id" value="<s:property value="#user.id"/>"> </div> </td> <td> <s:property value="#status.index+1" /><!-- 因爲從0開始,所以須要加1 --> </td> <td> <s:property value="#user.username" /> </td> <td> <s:property value="#user.password" /> </td> <td> <s:property value="#user.name" /> </td> <td> <s:property value="#user.email" /> </td> <td> <s:property value="#user.telephone" /> </td> <s:if test="#user.state==1"> <td class="td-status"> <span class="layui-btn layui-btn-normal layui-btn-mini">已啓用</span> </td> </s:if> <s:else> <td class="td-status"> <span class="layui-btn layui-btn-danger layui-btn-mini"> 未啓用 </span> </td> </s:else> <td> <s:property value="#user.level" /> </td>
package com.guiyan.domain; public class User { private String id; private String username; private String password; private String name; private String email; private String telephone; private Integer state; private String code; private String image; private Integer level; private Integer coin; private Integer isdelete; private String createtime; public String getId() { return id; } public void setId(String id) { this.id = id; } public String getUsername() { return username; } public void setUsername(String username) { this.username = username; } public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getEmail() { return email; } public void setEmail(String email) { this.email = email; } public String getTelephone() { return telephone; } public void setTelephone(String telephone) { this.telephone = telephone; } public String getCode() { return code; } public void setCode(String code) { this.code = code; } public String getImage() { return image; } public void setImage(String image) { this.image = image; } public Integer getLevel() { return level; } public void setLevel(Integer level) { this.level = level; } public Integer getCoin() { return coin; } public void setCoin(Integer coin) { this.coin = coin; } public Integer getIsdelete() { return isdelete; } public void setIsdelete(Integer isdelete) { this.isdelete = isdelete; } public String getCreatetime() { return createtime; } public void setCreatetime(String createtime) { this.createtime = createtime; } public Integer getState() { return state; } public void setState(Integer state) { this.state = state; } }
在domain建立一個User.hbm.xml
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"> <hibernate-mapping package="com.guiyan.domain"> <class name="User" table="user"> <id name="id"> <generator class="uuid"></generator> </id> <property name="username" column="username"></property> <property name="password" column="password"></property> <property name="name" column="name"></property> <property name="email" column="email"></property> <property name="telephone" column="telephone"></property> <property name="state" column="state"></property> <property name="code" column="code"></property> <property name="image" column="image"></property> <property name="level" column="level"></property> <property name="coin" column="coin"></property> <property name="isdelete" column="isdelete"></property> <property name="createtime" column="createtime"></property> </class> </hibernate-mapping>
統計共有的數據:
在user_list.jsp中寫入:
<span class="x-right" style="line-height: 40px"> 共有數據: <s:property value="#userPageBean.totalCount" /> 條 </span>
數據庫中用戶的數量爲:
當點擊用戶列表的時候,數據庫中的全部數據都會經過sql語句的查詢,將所須要的信息顯示在頁面上:
以上實現的分頁效果demo:
在user_list.jsp中進行修改成:
<div class="page"> <div> <a class="prev" href="${pageContext.request.contextPath }/UserAction_getPageBeanByCondition?currentPage=<s:property value="#userPageBean.currentPage-1"/> "><<</a> <s:if test="#userPageBean.currentPage-2>0"> <a class="num" href="${pageContext.request.contextPath }/UserAction_getPageBeanByCondition?currentPage=<s:property value="#userPageBean.currentPage-2"/> "> <s:property value="#userPageBean.currentPage-2" /> </a> </s:if> <s:if test="#userPageBean.currentPage-1>0"> <a class="num" href="${pageContext.request.contextPath }/UserAction_getPageBeanByCondition?currentPage=<s:property value="#userPageBean.currentPage-1"/>"> <s:property value="#userPageBean.currentPage-1" /> </a> </s:if> <span class="current"> <s:property value="#userPageBean.currentPage" /> </span> <s:if test="#userPageBean.currentPage+1<=#userPageBean.totalPage"> <a class="num" href="${pageContext.request.contextPath }/UserAction_getPageBeanByCondition?currentPage=<s:property value="#userPageBean.currentPage+1"/>"> <s:property value="#userPageBean.currentPage+1" /> </a> </s:if> <s:if test="#userPageBean.currentPage+2<=#userPageBean.totalPage"> <a class="num" href="${pageContext.request.contextPath }/UserAction_getPageBeanByCondition?currentPage=<s:property value="#userPageBean.currentPage+2"/>"> <s:property value="#userPageBean.currentPage+2" /> </a> </s:if> <a class="num" href="${pageContext.request.contextPath }/UserAction_getPageBeanByCondition?currentPage=<s:property value="#userPageBean.totalPage"/>>尾頁</a> <a class="next" href="${pageContext.request.contextPath }/UserAction_getPageBeanByCondition?currentPage=<s:property value="#userPageBean.currentPage+1"/>>>></a> </div> </div>
在UserAction.java中進行定義屬性:
private Integer currentPage; //獲得全部用戶 public String getAllUser() throws Exception { PageBean userPageBean = userService.getUserPageBean(currentPage); ActionContext.getContext().put("userPageBean", userPageBean); return "userList"; }