SSM下的分页

爱被打了一巴掌 2021-09-26 06:38 469阅读 0赞

页面:list.jsp

  1. <%@ page language="java" pageEncoding="UTF-8"%>
  2. <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
  3. <%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
  4. <%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags"%>
  5. <%@ taglib prefix="tags" tagdir="/WEB-INF/tags"%>
  6. <%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
  7. <script src="<c:url value="/js/jquery-ui.js"/>"></script>
  8. <script type="text/javascript">
  9. function buttonSubmit(url){
  10. document.form.action=url;
  11. document.form.submit();
  12. }
  13. function del(url){
  14. if(confirm("确定要删除该活动?")){
  15. document.form.action=url;
  16. document.form.submit();
  17. }
  18. }
  19. </script>
  20. <div class="app-content">
  21. <ul class="breadcrumb">
  22. <li>你当前的位置</li>
  23. <tags:breadcrumb />
  24. <li>列表</li>
  25. </ul>
  26. <div class="panel-group" id="accordion" role="tablist"
  27. aria-multiselectable="true">
  28. <div class="panel panel-default">
  29. <div class="panel-heading" role="tab" id="headingOne">
  30. <h4 class="panel-title" id="-collapsible-group-item-#1-">
  31. <a data-toggle="collapse" data-parent="#accordion"
  32. href="#collapseOne" aria-expanded="true"
  33. aria-controls="collapseOne" class=""> 活动方案列表 </a>
  34. </h4>
  35. </div>
  36. <div id="collapseOne" class="panel-collapse collapse in"
  37. role="tabpanel" aria-labelledby="headingOne" aria-expanded="true">
  38. <div class="panel-body">
  39. <form name="form" class="form-inline"
  40. action="<c:url value="/business/activity/list.do"/>" method="post">
  41. <fieldset>
  42. <div class="form-group form-group-sm right20">
  43. <label class="control-label" for="businessId">商户:</label> <select
  44. class="form-control" id="businessId" name="businessId">
  45. <option value="">--全部--</option>
  46. <c:forEach items="${business}" var="busines">
  47. <option value="${busines.id }" <c:if test="${condition.businessId == busines.id}">selected="selected"</c:if>>${busines.name }</option>
  48. </c:forEach>
  49. </select>
  50. </div>
  51. <div class="form-group form-group-sm right20">
  52. <label class="control-label" for="type">类型:</label> <select
  53. class="form-control" id="type" name="type">
  54. <option value="">--全部--</option>
  55. <option value="0" <c:if test="${condition.type == 0}">selected="selected"</c:if>>免费领取</option>
  56. <option value="1" <c:if test="${condition.type == 1}">selected="selected"</c:if>>商品秒杀</option>
  57. <option value="2" <c:if test="${condition.type == 2}">selected="selected"</c:if>>限时抢购</option>
  58. <option value="3" <c:if test="${condition.type == 3}">selected="selected"</c:if>>积分兑换</option>
  59. <option value="4" <c:if test="${condition.type == 4}">selected="selected"</c:if>>抽奖活动</option>
  60. <option value="5" <c:if test="${condition.type == 5}">selected="selected"</c:if>>转盘活动</option>
  61. <option value="6" <c:if test="${condition.type == 6}">selected="selected"</c:if>>会员商品</option>
  62. <option value="7" <c:if test="${condition.type == 7}">selected="selected"</c:if>>优惠券</option>
  63. <option value="8" <c:if test="${condition.type == 8}">selected="selected"</c:if>>注册送积分</option>
  64. <option value="9" <c:if test="${condition.type == 9}">selected="selected"</c:if>>合作方抽奖</option>
  65. <option value="10" <c:if test="${condition.type == 10}">selected="selected"</c:if>>看广告抽奖</option>
  66. </select>
  67. </div>
  68. <div class="form-group form-group-sm right20">
  69. <label class="control-label" for="title">标题:</label>
  70. <input class="form-control" type="text" id="title"
  71. name="title" value="${condition.title}">
  72. </div>
  73. <div class="form-group form-group-sm right20">
  74. <label class="control-label" for="status">状态:</label> <select
  75. class="form-control" id="status" name="status">
  76. <option value="">--全部--</option>
  77. <option value="0" <c:if test="${condition.status == 0}">selected="selected"</c:if>>上线</option>
  78. <option value="1" <c:if test="${condition.status == 1}">selected="selected"</c:if>>下线</option>
  79. </select>
  80. </div>
  81. <div class="form-group form-group-sm">
  82. <button type="submit" class="btn btn-primary btn-sm">
  83. <i class="icon-search icon-white"></i> 查 询
  84. </button>
  85. </div>
  86. <div class="form-group form-group-sm">
  87. <button type="button" οnclick="buttonSubmit('add.do')"
  88. class="btn btn-primary btn-sm">
  89. <i class="icon-search icon-white"></i> 添加方案
  90. </button>
  91. </div>
  92. </fieldset>
  93. </form>
  94. <table class="table table-striped table-bordered top20">
  95. <thead>
  96. <tr>
  97. <th>序号</th>
  98. <th>商户</th>
  99. <th>活动类型</th>
  100. <th>商品名称</th>
  101. <th>标题</th>
  102. <th>参与频率</th>
  103. <th>状态</th>
  104. <th>上线时间</th>
  105. <th>下线时间</th>
  106. <th>操作</th>
  107. </tr>
  108. </thead>
  109. <c:if test="${null != activityInfos}">
  110. <c:forEach var="item" items="${activityInfos}">
  111. <tr>
  112. <td class="center">${item.id}</td>
  113. <td class="center">
  114. <c:forEach items="${business }" var="busines">
  115. <c:if test="${busines.id == item.businessId }">${busines.name }</c:if>
  116. </c:forEach>
  117. </td>
  118. <td class="center">
  119. <c:choose>
  120. <c:when test="${item.type == 0}">免费领取</c:when>
  121. <c:when test="${item.type == 1}">商品秒杀</c:when>
  122. <c:when test="${item.type == 2}">限时抢购</c:when>
  123. <c:when test="${item.type == 3}">积分兑换</c:when>
  124. <c:when test="${item.type == 4}">抽奖活动</c:when>
  125. <c:when test="${item.type == 5}">转盘活动</c:when>
  126. <c:when test="${item.type == 6}">会员商品</c:when>
  127. <c:when test="${item.type == 7}">优惠券</c:when>
  128. <c:when test="${item.type == 8}">注册送积分</c:when>
  129. <c:when test="${item.type == 9}">合作方抽奖</c:when>
  130. <c:when test="${item.type == 10}">看广告抽奖</c:when>
  131. </c:choose>
  132. </td>
  133. <td class="center">
  134. <c:if test="${item.type != 4 && item.type != 5}">
  135. <c:forEach items="${commoditys}" var="commodity">
  136. <c:if test="${commodity.id == item.cid }">
  137. ${commodity.name}
  138. </c:if>
  139. </c:forEach>
  140. </c:if>
  141. <c:if test="${item.type == 4 or item.type == 9 or item.type == 10}">
  142. <a href="<c:url value="/business/lottery/list.do?aid=${item.id}"/>">查询奖品</a>
  143. </c:if>
  144. <c:if test="${item.type == 5}">
  145. <a href="<c:url value="/business/turntable/list.do?aid=${item.id}"/>">查询奖品</a>
  146. </c:if>
  147. </td>
  148. <td class="center" title="${item.title}">
  149. <c:if test="${fn:length(item.title)<=5}">
  150. ${item.title}
  151. </c:if>
  152. <c:if test="${fn:length(item.title)>5}">
  153. ${fn:substring(item.title, 0, 5)}...
  154. </c:if>
  155. </td>
  156. <td class="center">
  157. ${item.frequency}
  158. </td>
  159. <td class="center">
  160. <c:choose>
  161. <c:when test="${item.status == 0}">上线</c:when>
  162. <c:otherwise>下线</c:otherwise>
  163. </c:choose>
  164. </td>
  165. <td class="center">
  166. <fmt:formatDate value="${item.onlineTime}" pattern="yyyy-MM-dd HH:mm:ss"/>
  167. <td class="center">
  168. <fmt:formatDate value="${item.offlineTime}" pattern="yyyy-MM-dd HH:mm:ss"/>
  169. </td>
  170. <td>
  171. <%--<c:if test="${item.type == 1}">
  172. <button type="submit" class="btn btn-primary btn-xs"
  173. οnclick="buttonSubmit('/SG-web/business/spike/findByComm.do?activityId=${item.id}')">
  174. <i class="icon-edit icon-white"></i>设置秒杀规则
  175. </button>
  176. </c:if>--%>
  177. <c:if test="${item.status == 0 }">
  178. <button type="submit" class="btn btn-primary btn-xs"
  179. οnclick="buttonSubmit('offline.do?id=${item.id}')">
  180. <i class="icon-edit icon-white"></i>下线
  181. </button>
  182. </c:if>
  183. <c:if test="${item.status == 1 }">
  184. <button type="submit" class="btn btn-primary btn-xs"
  185. οnclick="buttonSubmit('online.do?id=${item.id}')">
  186. <i class="icon-edit icon-white"></i>上线
  187. </button>
  188. </c:if>
  189. <button type="submit" class="btn btn-primary btn-xs"
  190. οnclick="buttonSubmit('edit.do?id=${item.id}')">
  191. <i class="icon-edit icon-white"></i>编辑
  192. </button>
  193. <c:if test="${item.status == 1 }">
  194. <button type="submit" class="btn btn-primary btn-xs"
  195. οnclick="del('delete.do?id=${item.id}')">
  196. <i class="icon-edit icon-white"></i>删除
  197. </button>
  198. </c:if>
  199. </td>
  200. </tr>
  201. </c:forEach>
  202. </c:if>
  203. </table>
  204. <div style="text-align: right">
  205. <tags:page page1="${page}" />
  206. </div>
  207. </div>
  208. </div>
  209. </div>
  210. </div>
  211. </div

拦截器:com.fire.SG.web.interceptor/PageQueryInterceptor

package com.fire.SG.web.interceptor;

import com.fire.SG.web.util.page.Page;
import com.fire.SG.web.util.page.PageUtil;
import com.google.common.base.Joiner;
import org.apache.ibatis.executor.Executor;
import org.apache.ibatis.mapping.*;
import org.apache.ibatis.mapping.MappedStatement.Builder;
import org.apache.ibatis.plugin.*;
import org.apache.ibatis.session.ResultHandler;
import org.apache.ibatis.session.RowBounds;

import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
* Created by yb
*/
@Intercepts({@Signature(type = Executor.class, method = “query”, args = {MappedStatement.class, Object.class, RowBounds.class, ResultHandler.class})})
public class PageQueryInterceptor implements Interceptor {
private static final List EMPTY_RESULTMAPPING = new ArrayList(0);
@SuppressWarnings(“rawtypes”)
public Object intercept(Invocation invocation) throws Throwable {
//Page对象获取,“信使”到达拦截器!
Page page = PageUtil.getPage();
//不分页直接返回
if(page==null)
return invocation.proceed();

  1. //清空分页参数
  2. PageUtil.removePage();
  3. //当前环境 MappedStatement,BoundSql,及sql取得
  4. MappedStatement mappedStatement=(MappedStatement)invocation.getArgs()\[0\];
  5. BoundSql boundSql = mappedStatement.getBoundSql(invocation.getArgs()\[1\]);
  6. String originalSql = boundSql.getSql().trim();
  7. //查询总数
  8. String countSql = getCountSql(originalSql);
  9. BoundSql countBS = newBoundSql(mappedStatement, boundSql, countSql);
  10. MappedStatement countMs = newMappedStatement(mappedStatement, new BoundSqlSqlSource(countBS),true);
  11. invocation.getArgs()\[0\] = countMs;
  12. Object result = invocation.proceed();
  13. //设置总数
  14. page.setTotalRecord((Integer) ((List) result).get(0));
  15. //分页查询
  16. int pageNo = page.getPageNo();
  17. int pageSize = page.getPageSize();
  18. //分页计算
  19. //对原始Sql追加limit
  20. int offset = (pageNo - 1) \* pageSize;
  21. BoundSql newBoundSql = newBoundSql(mappedStatement, boundSql, originalSql + " limit " + offset + "," + pageSize);
  22. MappedStatement pageMs = newMappedStatement(mappedStatement, new BoundSqlSqlSource(newBoundSql),false);
  23. invocation.getArgs()\[0\]= pageMs;
  24. return invocation.proceed();
  25. \}
  26. /\*\*
  27. \* 新建MappedStatement对象
  28. \*/
  29. private MappedStatement newMappedStatement(MappedStatement ms, SqlSource newSqlSource,boolean count) \{
  30. Builder builder = new Builder(ms.getConfiguration(),ms.getId(),newSqlSource,ms.getSqlCommandType());
  31. builder.resource(ms.getResource());
  32. builder.fetchSize(ms.getFetchSize());
  33. builder.statementType(ms.getStatementType());
  34. builder.keyGenerator(ms.getKeyGenerator());
  35. if((ms.getKeyProperties()!=null))\{
  36. builder.keyProperty(Joiner.on(",").join(ms.getKeyProperties()));
  37. \}
  38. builder.timeout(ms.getTimeout());
  39. builder.parameterMap(ms.getParameterMap());
  40. if (count) \{
  41. //count查询返回值int
  42. List<ResultMap> resultMaps = new ArrayList<ResultMap>();
  43. ResultMap resultMap = new ResultMap.Builder(ms.getConfiguration(), ms.getId(), int.class, EMPTY\_RESULTMAPPING).build();
  44. resultMaps.add(resultMap);
  45. builder.resultMaps(resultMaps);
  46. \} else \{
  47. builder.resultMaps(ms.getResultMaps());
  48. \}
  49. builder.resultSetType(ms.getResultSetType());
  50. builder.cache(ms.getCache());
  51. builder.flushCacheRequired(ms.isFlushCacheRequired());
  52. builder.useCache(ms.isUseCache());
  53. return builder.build();
  54. \}
  55. /\*\*
  56. \* 复制BoundSql对象
  57. \*/
  58. private BoundSql newBoundSql(MappedStatement ms, BoundSql boundSql, String sql) \{
  59. BoundSql newBoundSql = new BoundSql(ms.getConfiguration(),sql, boundSql.getParameterMappings(), boundSql.getParameterObject());
  60. for (ParameterMapping mapping : boundSql.getParameterMappings()) \{
  61. String prop = mapping.getProperty();
  62. if (boundSql.hasAdditionalParameter(prop)) \{
  63. newBoundSql.setAdditionalParameter(prop, boundSql.getAdditionalParameter(prop));
  64. \}
  65. \}
  66. return newBoundSql;
  67. \}
  68. /\*\*
  69. \* 根据原Sql语句获取对应的查询总记录数的Sql语句
  70. \*/
  71. private String getCountSql(String sql) \{
  72. String copy = sql;
  73. Pattern pattern = Pattern.compile("order\\\\s+by.\*(asc|desc)?",Pattern.MULTILINE&Pattern.CASE\_INSENSITIVE);
  74. Matcher matcher = pattern.matcher(copy);
  75. copy = matcher.replaceAll("");
  76. return "SELECT COUNT(\*) FROM (" + copy + ") aliasForPage";
  77. \}
  78. public class BoundSqlSqlSource implements SqlSource \{
  79. BoundSql boundSql;
  80. public BoundSqlSqlSource(BoundSql boundSql) \{
  81. this.boundSql = boundSql;
  82. \}
  83. public BoundSql getBoundSql(Object parameterObject) \{
  84. return boundSql;
  85. \}
  86. \}
  87. public Object plugin(Object arg0) \{

// return this;
return Plugin.wrap(arg0, this);
}
public void setProperties(Properties arg0) {
}

  1. public static void main(String\[\] args) \{
  2. String s = "select c1,c2 from tbl\_test\_col Where c1=? order by c2 desc";
  3. System.out.println(testGetCountSql(s));
  4. \}
  5. //test
  6. private static String testGetCountSql(String sql) \{
  7. String copy = sql;
  8. Pattern pattern = Pattern.compile("order\\\\s+by.\*(asc|desc)?",Pattern.CASE\_INSENSITIVE&Pattern.MULTILINE);
  9. Matcher matcher = pattern.matcher(copy);
  10. copy = matcher.replaceAll("");
  11. return "SELECT COUNT(\*) FROM (" + copy + ") aliasForPage";
  12. \}

PageUtil Page

package com.fire.SG.web.util.page;

import com.alibaba.fastjson.JSON;
import com.google.common.base.Joiner;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.servlet.http.HttpServletRequest;
import java.io.UnsupportedEncodingException;
import java.util.List;
import java.util.Map;

/**
* Created by yubin
*/
public class Page {
private static final Logger logger = LoggerFactory.getLogger(Page.class);

  1. public static Integer DEFAULT\_PAGESIZE = 15;
  2. private int pageNo; //当前页码
  3. private int pageSize; //每页行数
  4. private int totalRecord; //总记录数
  5. private int totalPage; //总页数
  6. private Map<String, String> params; //查询条件
  7. private Map<String, List<String>> paramLists; //数组查询条件
  8. private String searchUrl; //Url地址
  9. private String pageNoDisp; //可以显示的页号(分隔符"|",总页数变更时更新)
  10. public Page() \{
  11. pageNo = 1;
  12. pageSize = DEFAULT\_PAGESIZE;
  13. totalRecord = 0;
  14. totalPage = 0;
  15. params = Maps.newHashMap();
  16. paramLists = Maps.newHashMap();
  17. searchUrl = "";
  18. pageNoDisp = "";
  19. \}
  20. public Page(int pageNo,int pageSize)\{
  21. this.pageNo = pageNo>0?pageNo:1;
  22. this.pageSize = pageSize>0?pageSize:DEFAULT\_PAGESIZE;
  23. totalRecord = 0;
  24. totalPage = 0;
  25. params = Maps.newHashMap();
  26. paramLists = Maps.newHashMap();
  27. searchUrl = "";
  28. pageNoDisp = "";
  29. \}
  30. public void initParams(HttpServletRequest req)\{
  31. String uri = req.getRequestURI();
  32. int pot = uri.indexOf(".do");
  33. // 从uri中抽取右侧"/"后字符串作为的acton名 例子中对应的是 "users"
  34. searchUrl=uri.substring(0,pot + 3);
  35. // 这里是核心代码:遍历 req.getParameterMap() 提取请求参数,要注意数组的情况
  36. for (Object key : req.getParameterMap().keySet()) \{
  37. String\[\] args = req.getParameterValues(key.toString());
  38. if (args.length > 1) \{
  39. paramLists.put(key.toString(), convertParamArr(args, req));
  40. \} else \{
  41. params.put(key.toString(), convertIsoToUtf8(req.getParameter(key.toString()), req));
  42. \}
  43. \}
  44. if (params.get("pageNo") == null) \{
  45. params.put("pageNo", "1"); // 当前页 缺省值设定
  46. \} else \{
  47. pageNo= Integer.parseInt(params.get("pageNo"));
  48. // 点击分页标签时的请求 编辑totalRecord 项目(避免重复查询总记录数)
  49. totalRecord=Integer.parseInt(params.get("totalRecord"));
  50. \}
  51. \}
  52. /\*\*
  53. \* GET请求时,单个入参的转码处理
  54. \*/
  55. private static String convertIsoToUtf8(String strIn, HttpServletRequest request) \{
  56. if (strIn == null || !request.getMethod().equalsIgnoreCase("get")) \{
  57. return strIn;
  58. \}
  59. try \{
  60. return new String(strIn.getBytes("iso-8859-1"), "utf-8");
  61. \} catch (UnsupportedEncodingException e) \{
  62. return strIn;
  63. \}
  64. \}
  65. /\*\*
  66. \* GET请求时,数组型入参的转码处理
  67. \*/
  68. private static List<String> convertParamArr(String\[\] param,
  69. HttpServletRequest request) \{
  70. List<String> list = Lists.newArrayList();
  71. if (param != null) \{
  72. for (String p : param) \{
  73. String convertP = convertIsoToUtf8(p, request);
  74. if (!list.contains(convertP)) \{
  75. list.add(convertP);
  76. \}
  77. \}
  78. \}
  79. return list;
  80. \}
  81. /\*\*
  82. \* 查询条件转JSON
  83. \*/
  84. public String getParaJson() \{
  85. Map<String, Object> map = Maps.newHashMap();
  86. for (String key : params.keySet()) \{
  87. if (params.get(key) != null) \{
  88. map.put(key, params.get(key));
  89. \}
  90. \}
  91. String json = "";
  92. try \{
  93. json = JSON.toJSONString(map);
  94. \} catch (Exception e) \{
  95. logger.error("转换JSON失败", params, e);
  96. \}
  97. return json;
  98. \}
  99. /\*\*
  100. \* 数组查询条件转JSON
  101. \*/
  102. public String getParaListJson() \{
  103. Map<String, Object> map = Maps.newHashMap();
  104. for (String key : paramLists.keySet()) \{
  105. List<String> lists = paramLists.get(key);
  106. if (lists != null && lists.size() > 0) \{
  107. map.put(key, lists);
  108. \}
  109. \}
  110. String json = "";
  111. try \{
  112. json = JSON.toJSONString(map);
  113. \} catch (Exception e) \{
  114. logger.error("转换JSON失败", params, e);
  115. \}
  116. return json;
  117. \}
  118. /\*\*
  119. \* 总件数变化时,更新总页数并计算显示样式
  120. \*/
  121. private void refreshPage() \{
  122. //总页数计算
  123. totalPage = totalRecord % pageSize == 0 ? totalRecord / pageSize : (totalRecord / pageSize + 1);
  124. //防止超出最末页(浏览途中数据被删除的情况)
  125. if (pageNo > totalPage && totalPage != 0) \{
  126. pageNo = totalPage;
  127. \}
  128. pageNoDisp = computeDisplayStyleAndPage();
  129. \}
  130. /\*\*
  131. \* 计算页号显示样式
  132. \* 这里实现以下的分页样式("\[\]"代表当前页号),可根据项目需求调整
  133. \* \[1\],2,3,4,5,6,7,8..12,13
  134. \* 1,2..5,6,\[7\],8,9..12,13
  135. \* 1,2..6,7,8,9,10,11,12,\[13\]
  136. \*/
  137. private String computeDisplayStyleAndPage() \{
  138. List<Integer> pageDisplays = Lists.newArrayList();
  139. if (totalPage <= 11) \{
  140. for (int i = 1; i <= totalPage; i++) \{
  141. pageDisplays.add(i);
  142. \}
  143. \} else if (pageNo < 7) \{
  144. for (int i = 1; i <= 8; i++) \{
  145. pageDisplays.add(i);
  146. \}
  147. pageDisplays.add(0);// 0 表示 省略部分(下同)
  148. pageDisplays.add(totalPage - 1);
  149. pageDisplays.add(totalPage);
  150. \} else if (pageNo > totalPage - 6) \{
  151. pageDisplays.add(1);
  152. pageDisplays.add(2);
  153. pageDisplays.add(0);
  154. for (int i = totalPage - 7; i <= totalPage; i++) \{
  155. pageDisplays.add(i);
  156. \}
  157. \} else \{
  158. pageDisplays.add(1);
  159. pageDisplays.add(2);
  160. pageDisplays.add(0);
  161. for (int i = pageNo - 2; i <= pageNo + 2; i++) \{
  162. pageDisplays.add(i);
  163. \}
  164. pageDisplays.add(0);
  165. pageDisplays.add(totalPage - 1);
  166. pageDisplays.add(totalPage);
  167. \}
  168. return Joiner.on("|").join(pageDisplays.toArray());
  169. \}
  170. public int getPageNo() \{
  171. return pageNo;
  172. \}
  173. public void setPageNo(int pageNo) \{
  174. this.pageNo = pageNo;
  175. \}
  176. public int getPageSize() \{
  177. return pageSize;
  178. \}
  179. public void setPageSize(int pageSize) \{
  180. this.pageSize = pageSize;
  181. \}
  182. public int getTotalRecord() \{
  183. return totalRecord;
  184. \}
  185. public void setTotalRecord(int totalRecord) \{
  186. this.totalRecord = totalRecord;
  187. refreshPage();
  188. \}
  189. public int getTotalPage() \{
  190. return totalPage;
  191. \}
  192. public void setTotalPage(int totalPage) \{
  193. this.totalPage = totalPage;
  194. \}
  195. public Map<String, String> getParams() \{
  196. return params;
  197. \}
  198. public void setParams(Map<String, String> params) \{
  199. this.params = params;
  200. \}
  201. public Map<String, List<String>> getParamLists() \{
  202. return paramLists;
  203. \}
  204. public void setParamLists(Map<String, List<String>> paramLists) \{
  205. this.paramLists = paramLists;
  206. \}
  207. public String getSearchUrl() \{
  208. return searchUrl;
  209. \}
  210. public void setSearchUrl(String searchUrl) \{
  211. this.searchUrl = searchUrl;
  212. \}
  213. public String getPageNoDisp() \{
  214. return pageNoDisp;
  215. \}
  216. public void setPageNoDisp(String pageNoDisp) \{
  217. this.pageNoDisp = pageNoDisp;
  218. \}

}

package com.fire.SG.web.util.page;

import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;

/**
* 只能对接下来的一个进行分页,
* Created by yubin
*/
public class PageUtil {
private static ThreadLocal threadPage = new ThreadLocal();

  1. public static Page getPage () \{
  2. return threadPage.get();
  3. \}
  4. public static Page removePage () \{
  5. Page page = threadPage.get();
  6. threadPage.set(null);
  7. return page;
  8. \}
  9. /\*\*
  10. \* 开始分页,只能对接下来的一个进行分页
  11. \*/
  12. public static Page startPage(Page page)\{
  13. threadPage.set(page);
  14. initPageParam(page);
  15. return page;
  16. \}
  17. /\*\*
  18. \* 开始分页,只能对接下来的一个进行分页
  19. \*/
  20. public static Page startPage(int pageNo,int pageSize) \{
  21. Page page = new Page(pageNo,pageSize);
  22. return startPage(page);
  23. \}
  24. private static void initPageParam(Page page)\{
  25. HttpServletRequest req = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
  26. page.initParams(req);
  27. \}

}

发表评论

表情:
评论列表 (有 0 条评论,469人围观)

还没有评论,来说两句吧...

相关阅读

    相关 Layui + ssm

    做后台就会涉及到表格数据,当数据多的时候,就要使用分页来显示,这样就显得比较美观。分页确实有效,但它一定会加大系统的复杂度,如果数据量少的话可以不用分页,但是对于企业信息系统来

    相关 ssm查询

    引言:基于ssm框架下,利用Mybaits插件PageHelper进行分页查询,可以省去大量繁琐的代码,操作起来更为方便, 1、数据库表的设计 ![70][] ---

    相关 ssm框架查询

    一、开发项目时,对于多条记录的显示,我们采用分页查询将会更加方便。 二、基于ssm框架,我们通过一个记录的起始值start,和记录的大小size封装到一个list集合里