1 package com.dy.cloudticket.web.controller.system; 2 3 import java.util.HashMap; 4 import java.util.Iterator; 5 import java.util.Map; 6 7 import javax.servlet.http.HttpServletRequest; 8 9 import org.springframework.stereotype.Controller; 10 import org.springframework.web.context.request.RequestContextHolder; 11 import org.springframework.web.context.request.ServletRequestAttributes; 12 13 @Controller 14 public class BaseController { 15 /** 16 * 获取参数 17 * @return 18 */ 19 public Map<String,Object> getParameter(){ 20 HttpServletRequest request=this.getRequest(); 21 Map properties = request.getParameterMap(); 22 Map returnMap = new HashMap(); 23 Iterator entries = properties.entrySet().iterator(); 24 Map.Entry entry; 25 String name = ""; 26 String value = ""; 27 while (entries.hasNext()) { 28 entry = (Map.Entry) entries.next(); 29 name = (String) entry.getKey(); 30 Object valueObj = entry.getValue(); 31 if(null == valueObj){ 32 value = ""; 33 }else if(valueObj instanceof String[]){ 34 String[] values = (String[])valueObj; 35 for(int i=0;i<values.length;i++){ 36 value = values[i] + ","; 37 } 38 value = value.substring(0, value.length()-1); 39 }else{ 40 value = valueObj.toString(); 41 } 42 returnMap.put(name, value); 43 } 44 properties = returnMap; 45 return properties; 46 } 47 48 /**获取request对象 49 * @return 50 */ 51 public HttpServletRequest getRequest() { 52 HttpServletRequest request = ((ServletRequestAttributes)RequestContextHolder.getRequestAttributes()).getRequest(); 53 return request; 54 } 55 }