@RequestParam和@RequestBody

@RequestParam用来处理简单类型的绑定,由ConversionService配置的转换器来完成,用来处理Conten-Type为:application/x-www-form-urlencoded编码的内容,提交方式为get,post.

该注解有两个参数,value,required,value是用来指定要传入的值的id名称,required指定参数是否需要绑定。

@RequestBody用来处理Content-type:不是application/x-www-form-urlencoded编码的内容,例如application/json, application/xml等;

它是通过使用HandlerAdapter 配置的HttpMessageConverters来解析post data body,然后绑定到相应的bean上的。

因为配置有FormHttpMessageConverter,所以也可以用来处理 application/x-www-form-urlencoded的内容,处理完的结果放在一个MultiValueMap<String, String>里,这种情况在某些特殊需求下使用,详情查看FormHttpMessageConverter api;

猜你喜欢

转载自jackmei.iteye.com/blog/2311149