自实现后台动态请求参数:getParam

/**
 * 得到request对象
 */
public HttpServletRequest getRequest() {
	HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
	return request;
}
/*
 * 得到参数Map
 */
public Map getParam(HttpServletRequest req)
{
	Map param=req.getParameterMap();
	Map map=new HashMap();
	Set> sets=param.entrySet();
	for (Entry entry : sets) {
		String key=entry.getKey();
		Object valObj=entry.getValue();
		String value="";
		if(null==valObj)
		{
			value="";
		}
		else if(valObj instanceof String[])
		{
			String[] values=(String[]) valObj;
			for (String string : values) {
				value+=string+",";
			}
			value= value.substring(0, value.length()-1);
		}
		else
		{
			value=valObj.toString();
		}
		map.put(key, value);
	}
	return map; 
}
/*
 * 调用
 */
public static Map getMap(){
	return getParam(getRequest());
}


@RequestMapping("/……")
@ResponseBody
public …… getInfoDetail(){
	
	Map param=getMap();
	
	……
}

 

 

你可能感兴趣的:(java)