SpringMVC信息转换--处理XML和JSON
来源:互联网 发布:网络舆论引导的重要性 编辑:程序博客网 时间:2024/05/22 12:32
SpringMVC提供了几个处理XML和JSON格式的请求/响应信息的HttpMessageConverter:
只要在Spring WEB容器中为RequestMappingHandlerAdapter装配好相应的处理XML和JSON格式的请求/响应消息的HttpMessageConverter,并在交互中通过请求的Accept指定MIME类型,SpringMVC就可以使用服务器端的处理方法和客户端透明的通过XML和JSON格式的消息进行通信。
一、在WEB上下文中装配处理XML和JSON格式的请求/响应消息的HttpMessageConverter。
1.1、需要用到的jar包
<dependency> <groupId>com.thoughtworks.xstream</groupId> <artifactId>xstream</artifactId> <version>1.4.10</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-oxm</artifactId> <version>4.3.10.RELEASE</version> </dependency>
1.2、web上下文中的配置
<bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter" p:messageConverters-ref="messageConverters"/> <util:list id="messageConverters"> <bean class="org.springframework.http.converter.BufferedImageHttpMessageConverter"/> <bean class="org.springframework.http.converter.ByteArrayHttpMessageConverter"/> <bean class="org.springframework.http.converter.StringHttpMessageConverter"/> <bean class="org.springframework.http.converter.support.AllEncompassingFormHttpMessageConverter"/><!--装配解析XML和JSON的HttpMessageConverter--> <bean class="org.springframework.http.converter.xml.MarshallingHttpMessageConverter" p:marshaller-ref="xmlMarshaller" p:unmarshaller-ref="xmlMarshaller"/> <bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter"/> </util:list> <bean id="xmlMarshaller" class="org.springframework.oxm.xstream.XStreamMarshaller"> <property name="streamDriver"> <bean class="com.thoughtworks.xstream.io.xml.StaxDriver"/> </property> <property name="annotatedClasses"> <list> <!--需要被绑定信息的类--> <value>com.smart.bean.User</value> </list> </property> </bean>
(待定)
阅读全文
0 0
- SpringMVC信息转换--处理XML和JSON
- SpringMVC处理XML和JSON遇到的问题及解决
- SpringMVC返回XML和JSON
- 【SpringMVC】SpringMvc基础-常用注解、对象和json或xml之间的转换
- 【SpringMVC】SpringMvc基础-常用注解、对象和json或xml之间的转换
- JSON和XML格式转换
- SpringMVC中使用@RequestBody,@ResponseBody注解实现Java对象和XML/JSON数据自动转换)
- php 处理json 和 xml
- SpringMVC 产生XML视图和JSON视图
- spring和springMVC中xml文件信息
- springmvc接收和处理json数据
- SpringMVC关于json、xml自动转换的原理研究
- SpringMVC关于json、xml自动转换的原理研究
- SpringMVC关于json、xml自动转换的原理研究
- 【springmvc】关于xml,json自动转换的原理研究
- SpringMVC关于json、xml自动转换的原理研究
- SpringMVC关于json、xml自动转换的原理研究
- SpringMVC中使用@RequestBody,@ResponseBody注解实现Java对象和XML/JSON数据自动转换(上)
- 校招拼多多笔试题(前端工程师)
- 最小K个数
- Mockito 学习篇(四)完结
- js深拷贝与浅拷贝
- leetcode 33. Search in Rotated Sorted Array 二分查找
- SpringMVC信息转换--处理XML和JSON
- MAC上查看PDM文件
- Linux下rsync 安装与配置
- 摸底
- 剑指OFFER纪念版(5)
- JavaWeb不要使用Eclipse内置浏览器!好处:F12检查JavaWeb页面代码Bug和避免“假的bug”
- Hadoop核心模块之MapReduce
- R语言常用图形设备管理函数
- JAVA实现两个变量间的互换