SpringMVC 中 HttpMessageConverter<T>
来源:互联网 发布:阿里云9月推荐码 编辑:程序博客网 时间:2024/04/28 18:47
HttpMessageConverter负责将请求信息转换为一个对象(类型为T),将对象(类型为T)输出为响应信息。
下面我们说一下如何使用。
使用HttpMessageConverter将请求信息转化并绑定到处理方法的入参中或将响应结果转为对应类型的响应信息,SpringMVC提供了两种途径:
- 使用@RequestBody或@ResponseBody对处理方法进行标注
- 使用HttpEntity< T >或 ResponseEntity< T >作为处理方法的入参或返回值
说明:不需要成对的出现。
当控制器处理方法使用到@RequestBody或@ResponseBody或HttpEntity< T >或ResponseEntity< T >时,SpringMVC首先根据请求头或者响应头的Accept属性选择匹配的HttpMessageConverter,进而根据参数类型或泛型类型的过滤得到匹配的HttpMessageConverter,若找不到可用的HttpMessageConverter将报错。
我们看看实例。
前台index.jsp加一句就行
<a href="testResponseEntity">Test ResponseEntity </a>
就会把文件下载下来。
1 0
- SpringMVC 中 HttpMessageConverter<T>
- springmvc之HttpMessageConverter<T>接口
- HttpMessageConverter<T>
- springMVC源码4:HttpMessageConverter<T>和ConversionService之间怎么关联
- springMVC源码5:HttpMessageConverter<T>和ConversionService之间怎么关联
- SpringMVC之HttpMessageConverter
- springmvc之HttpMessageConverter
- [SpringMVC] HttpMessageConverter配置
- HttpMessageConverter<T>接口源码学习
- SpringMVC处理Json-使用 HttpMessageConverter
- SpringMVC 流程(4)-- HttpMessageConverter
- SpringMVC源码-消息转换器HttpMessageConverter
- SpringMVC处理Json-使用 HttpMessageConverter
- SpringMVC 中HttpMessageConverter简介和Http请求415 Unsupported Media Type的问题
- SpringMVC 中HttpMessageConverter简介和Http请求415 Unsupported Media Type的问题
- SpringMVC 中HttpMessageConverter简介和Http请求415 Unsupported Media Type的问题
- SpringMVC 中HttpMessageConverter简介和Http请求415 Unsupported Media Type的问题
- HttpMessageConverter
- 使用Octave音频处理(一):对文件进行读写操作
- POJ 2301 Beat the Spread! G++
- android系统角标显示
- intellj idea 如何设置类头注释和方法注释
- PAT A 1035
- SpringMVC 中 HttpMessageConverter<T>
- 为什么还差一点?
- js一些算法集合 储备学习
- 2016届新生培训
- 获取xml中的 (一部分报文节点)循环组的文本内容
- 第三方APP微信登陆时无法调起授权页面的终极坑
- 设备I/O控制方式
- tomcat系列-02-基础操作
- 高并发高负载系统架构