Spring MVC中@RequestParam注解

spring MVC开发中,使用ajax发送数据的时候,直接getGrouponPrice(HttpServletRequest request)使用request就可以获取到数据了,但是在使用表单提交的时候,使用request获取不到数据,后来使用@RequestParam注解配合map才获取到了数据。

@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用来指示参数是否必须绑定;

@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();

}

值得一提的是,使用下面的方式也获取不到数据:

@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

转载于:https://my.oschina.net/hehongbo/blog/734741

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值