Spring MVC的自动转换功能 HttpMessageConverter
来源:互联网 发布:合金装备 mac 汉化 编辑:程序博客网 时间:2024/06/05 18:15
Spring MVC的自动转换功能 HttpMessageConverter
默认起用的MVC注解功能
StringHttpMessageConverter: that can read and write Strings from the HTTP request and response.
FormHttpMessageConverter:that can read and write form data from the HTTP request and response.
ByteArrayMessageConverter:that can read and write byte arrays from the HTTP request and response.
MarshallingHttpMessageConverter:XML的转换需要使用Spring的 Marshaller 和 Unmarshaller.
MappingJacksonHttpMessageConverter:JSON的转换.
SourceHttpMessageConverter:能够读/写来自HTTP的请求与响应的javax.xml.transform.Source ,支持DOMSource, SAXSource, 和 StreamSource 的XML格式
BufferedImageHttpMessageConverter:that can read and write java.awt.image.BufferedImage from the HTTP request and response
起用JSON转换功能
xml
1 <!-- 启动Spring MVC的注解功能,完成请求和注解POJO的映射 --> 2 <bean 3 class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"> 4 <property name="messageConverters"> 5 <util:list id="beanList"> 6 <ref bean="stringHttpMessageConverter" /> 7 <ref bean="jsonHttpMessageConverter" /> 8 <ref bean="marshallingHttpMessageConverter" /> 9 </util:list>10 </property>11 </bean>12 13 <bean id="stringHttpMessageConverter"14 class="org.springframework.http.converter.StringHttpMessageConverter" />15 <bean id="jsonHttpMessageConverter"16 class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter" />17 <bean id="marshallingHttpMessageConverter"18 class="org.springframework.http.converter.xml.MarshallingHttpMessageConverter">19 <property name="marshaller" ref="castorMarshaller" />20 <property name="unmarshaller" ref="castorMarshaller" />21 </bean>22 23 <bean id="castorMarshaller" class="org.springframework.oxm.castor.CastorMarshaller" />24
MappingJacksonHttpMessageConverter能够将POJO对象自动转换为JSON对象 @RequestMapping(value = "/getPojoJson" , method=RequestMethod.GET) public @ResponseBody Pojo getPojoJson() { Pojo pojo=new Pojo(); pojo.setA("test"); pojo.setB(1); pojo.setD(new Date()); return pojo; }
需要依赖JSON对象的处理JAR包
jackson-core-lgpl.jar
jackson-mapper-lgpl.jar
下载地址:
http://jackson.codehaus.org/
- Spring MVC的自动转换功能 HttpMessageConverter
- Spring MVC的自动转换功能 HttpMessageConverter
- Spring MVC的自动转换功能 HttpMessageConverter
- Spring MVC的自动转换功能 HttpMessageConverter
- Spring MVC的自动转换功能 HttpMessageConverter
- spring mvc HttpMessageConverter使用
- 使用 Spring 3 MVC HttpMessageConverter 功能构建 RESTful web 服务
- 使用 Spring 3 MVC HttpMessageConverter 功能构建 RESTful web 服务
- 使用 Spring 3 MVC HttpMessageConverter 功能构建 RESTful web 服务
- 使用 Spring 3 MVC HttpMessageConverter 功能构建 RESTful web 服务
- 使用 Spring 3 MVC HttpMessageConverter 功能构建 RESTful web 服务
- Spring 3 MVC HttpMessageConverter 功能构建 RESTful web 服务
- Spring MVC4.1-Spring MVC的配置(含自定义HttpMessageConverter)
- spring-mvc 请求body 的处理方式 HttpMessageConverter
- Spring MVC的HTTP请求信息转换器HttpMessageConverter
- String3 MVC-----使用 Spring 3 MVC HttpMessageConverter 功能构建 RESTful web 服务
- SPRING MVC3.2案例讲解--使用 Spring 3 MVC HttpMessageConverter 功能构建 RESTful web 服务
- SPRING MVC3.2案例讲解--使用 Spring 3 MVC HttpMessageConverter 功能构建 RESTful web 服务
- 关于ie8的滤镜
- 小小的IP,大大的耦合
- 524. Longest Word in Dictionary through Deleting
- 1052. 卖个萌 (20) PAT乙级真题
- ANR 分析解决
- Spring MVC的自动转换功能 HttpMessageConverter
- JAVA调用ImageCapOnWeb控件实现拍照功能
- angular API
- 最小树形图
- 如何一次终止同一名字的多个进程
- 分布式缓存Redis之配置文件redis.conf详解
- 设计模式(十四)——备忘录模式
- A07_文本文件的读写
- android Logcat打印格式说明