SpringMVC 流程(4)-- HttpMessageConverter

本文研究的一个问题就是request请求的参数是怎么来到我们的方法参数中的,以及我们的方法参数是怎么又去到response响应中的。

一. @RequestBody,@ResponseBody

@RequestBody
   
   
Annotation indicating a method parameter should be bound to the body of the web request. 
The body of the request is passed through an HttpMessageConverter to resolve the method argument depending on the content type of the request. Optionally, automatic validation can be 
    applied by annotating the argument with @Valid.
Supported for annotated handler methods in Servlet environments.
          也就是说,该注解表明方法的参数和请求request 的 请求正文相绑定。请求正文会根据请求头的content-Type通过 HttpMessageConverter 对象来转换到方法参数中。有一个可选项就是我们可以通过@Valid 注解来对参数进行验证。

@ResponseBody
     将内容或对象作为 HTTP 响应正文返回,使用@ResponseBody将会跳过视图处理部分,而是调用适合HttpMessageConverter,将返回值写入输出流。

二. HttpMessageConverter

参考该文章,写得比较深入和具体(建议也看下它的这个系列的文章): http://my.oschina.net/lichhao/blog/172562




  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值