package cn.xhsd.util.split; import javax.servlet.http.HttpServletRequest; import cn.xhsd.action.abs.AbstractAction; public class SplitUtil { private int cp = 1; private int ls = 3; private String col; private String kw; private AbstractAction action; public SplitUtil(AbstractAction action) { // 取得公共的Action this.action = action; } public void setCp(String cp) { try { this.cp = Integer.parseInt(cp); } catch (Exception e) { } } public void setLs(String ls) { try { this.ls = Integer.parseInt(ls); } catch (Exception e) { } } public void setCol(String col) { if (col == null || "".equals(col)) { this.col = this.action.getDefaultColumn(); } else { this.col = col; } } public void setKw(String kw) { if ("".equals(kw) || kw == null) { this.kw = ""; } else { this.kw = kw; } } public int getCurrentPage() { return cp; } public int getLineSize() { return ls; } public String getColumn() { return col; } public String getKeyword() { return kw; } /** * 将查询的数据和记录数据设置到页面中 * @param request * @param allRecorders * @param url * @param paramA * @param valueA * @param paramB * @param valueB */ public void setAttribute(HttpServletRequest request, Object allRecorders, String url, String paramA, Object valueA, String paramB, Object valueB) { request.setAttribute("allRecorders", allRecorders); request.setAttribute("url", url); request.setAttribute("paramName", paramA); request.setAttribute("paramValue", valueA); request.setAttribute("paramNameB", paramB); request.setAttribute("paramValueB", valueB); } } /** * 专门抽取action中公有的属性或方法 * @author fy * @version 1.0 */ public abstract class AbstractAction { /** * SpringMVC 分页 * @param request * @param currentPage * @param lineSize * @param column * @param keyWord * @param split */ public void handleSplit1(HttpServletRequest request,Integer currentPage,Integer lineSize,String column,String keyWord,SplitUtil split) { split.setCp(String.valueOf(currentPage)); split.setLs(String.valueOf(lineSize)); split.setKw(keyWord); split.setCol(column); // 将这些内容传递到JSP页面上 request.setAttribute("currentPage", split.getCurrentPage()); request.setAttribute("lineSize", split.getLineSize()); request.setAttribute("column", split.getColumn()); request.setAttribute("keyWord", split.getKeyword()); request.setAttribute("columnData", this.getColumnData()); } @RequestMapping("listBySplit") public ModelAndView listBySplit( @RequestParam(value="cp",defaultValue="1") Integer currentPage, @RequestParam(value="ls",defaultValue="3") Integer lineSize, @RequestParam(value="col",defaultValue="title") String column, @RequestParam(value="kw",defaultValue="") String keyWord, HttpServletRequest request ){ ModelAndView mav=new ModelAndView(); Map<String,Object> map = this.bikeBackService.listBySplit(currentPage,lineSize,column,keyWord); @SuppressWarnings("unchecked") List<Bike> allBikes=(List<Bike>)map.get("allBikes"); Integer allCounts=(Integer)map.get(("allCounts")); System.out.println("counts= "+allCounts); //此操作是将分页数据和筛选数据回填返回到页面 SplitUtil splitUtil = new SplitUtil(this); super.handleSplit1(request, currentPage, lineSize, column, keyWord, splitUtil); //此操作是将查询的数据和记录数返回到页面 splitUtil.setAttribute(request, allCounts, "BikeBackAction/listBySplit.action", null, null, null, null); mav.setViewName("/pages/bike/bike_list.jsp"); mav.addObject("allBikes",allBikes); return mav; }