Spring MVC中@RequestParam註解

spring MVC開發中,使用ajax發送數據的時候,直接getGrouponPrice(HttpServletRequest request)使用request就能夠獲取到數據了,可是在使用表單提交的時候,使用request獲取不到數據,後來使用@RequestParam註解配合map才獲取到了數據。ajax

@RequestParam A) 經常使用來處理簡單類型的綁定,經過Request.getParameter() 獲取的String可直接轉換爲簡單類型的狀況( String--> 簡單類型的轉換操做由ConversionService配置的轉換器來完成);由於使用request.getParameter()方式獲取參數,因此能夠處理get 方式中queryString的值,也能夠處理post方式中 body data的值; B)用來處理Content-Type: 爲 application/x-www-form-urlencoded編碼的內容,提交方式GET、POST; C) 該註解有兩個屬性: value、required; value用來指定要傳入值的id名稱,required用來指示參數是否必須綁定;spring

@RequestMapping(value="/saveInfo",method=RequestMethod.POST)
public ModelAndView saveInfo(@RequestParam Map<String,Object> params) throws URIException {
		
		String cityName = params.get("input_cityName").toString();
		String carId = params.get("input_carId").toString();
		String ids = params.get("input_ids").toString();
		String name = params.get("input_name").toString();
		String phone = params.get("input_phone").toString();
		String price = params.get("input_price").toString();
		String channel = params.get("channel").toString();
		String appsku = params.get("appsku").toString();

}

值得一提的是,使用下面的方式也獲取不到數據:app

@RequestParam(value = "input_cityName", required = true) String cityName,
@RequestParam(value = "input_carId", required = true) String carId,
@RequestParam(value = "input_ids", required = true) String ids,
@RequestParam(value = "input_name", required = true) String name,
@RequestParam(value = "input_phone", required = true) String phone,
@RequestParam(value = "input_price", required = true) String price,
@RequestParam(value = "channel", required = true) String channel,
@RequestParam(value = "appsku", required = true) String appsku

@RequestParam("input_cityName") String cityName,
@RequestParam("input_carId") String carId,
@RequestParam("input_ids") String ids,
@RequestParam("input_name") String name,
@RequestParam("input_phone") String phone,
@RequestParam("input_price") String price,
@RequestParam("channel") String channel,
@RequestParam("appsku") String appsku
相關文章
相關標籤/搜索