SpringMVC收发带CDATA的xml报文
来源:互联网 发布:淘宝积分不能登录 编辑:程序博客网 时间:2024/05/22 15:34
首先需要引入eclipselink包:
<span style="white-space:pre"></span><dependency><groupId>org.eclipse.persistence</groupId><artifactId>eclipselink</artifactId><version>2.5.0</version></dependency>实体类包下面需要添加jaxb.properties文件:
javax.xml.bind.context.factory=org.eclipse.persistence.jaxb.JAXBContextFactory
实体类使用如下注解:
package com.chinamobile.cmss.ehub.ssb.test.entity;import javax.xml.bind.annotation.XmlAccessType;import javax.xml.bind.annotation.XmlAccessorType;import javax.xml.bind.annotation.XmlRootElement;import org.eclipse.persistence.oxm.annotations.XmlCDATA;@XmlRootElement(name="InterBOSS")@XmlAccessorType(XmlAccessType.FIELD)public class UserStateRqeMessage {@XmlCDATAprivate String SvcCont;public String getSvcCont() {return SvcCont;}public void setSvcCont(String svcCont) {SvcCont = svcCont;}/*private UserStateDetail SvcCont;public UserStateDetail getSvcCont() {return SvcCont;}public void setSvcCont(UserStateDetail svcCont) {SvcCont = svcCont;}*/}controller接口使用@ResponseBody和@RequestBody
package com.chinamobile.cmss.ehub.ssb.test.controller;import javax.xml.bind.JAXBContext;import javax.xml.bind.JAXBException;import javax.xml.bind.Marshaller;import org.springframework.stereotype.Controller;import org.springframework.web.bind.annotation.RequestBody;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RequestMethod;import org.springframework.web.bind.annotation.ResponseBody;import com.chinamobile.cmss.ehub.ssb.test.entity.UserStateRqeMessage;import com.chinamobile.cmss.ehub.ssb.test.entity.UserStateRspMessage;@Controllerpublic class UserController {@ResponseBody@RequestMapping(value="/users", method=RequestMethod.POST)public UserStateRspMessage checkUserState(@RequestBody UserStateRqeMessage userStateRqeMessage) throws JAXBException{System.out.println(userStateRqeMessage.getSvcCont());JAXBContext jc = JAXBContext.newInstance(UserStateRspMessage.class);UserStateRspMessage userStateRspMessage = new UserStateRspMessage();Marshaller marshaller = jc.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); marshaller.marshal(userStateRspMessage, System.out); return userStateRspMessage;}}
0 0
- SpringMVC收发带CDATA的xml报文
- php解析带CDATA的XML
- PHP解析带CDATA的XML方法
- dom4j生成XML报文以及CDATA值的设置
- 如何用XSLT生成带CDATA段的xml文档
- XML CDATA的作用
- XML CDATA 的应用
- XML CDATA的作用
- xml的CDATA 区段
- XML CDATA的作用
- XML CDATA的作用
- XML CDATA的作用
- XML CDATA的作用
- XML CDATA的作用
- XML CDATA的作用
- xml cdata的作用
- JAVA JDOM解析XML 带CDATA数据
- XML CDATA的有关说明
- 基于go语言的消息推送系统架构分析
- JavaScript 运算符
- c++ virtual关键字详解
- Android ImageView加载摄像头拍摄的大图
- linux下利用vsftpd搭建ftp服务器
- SpringMVC收发带CDATA的xml报文
- leetcode | Maximum Depth of Binary Tree
- greenplum安装参考笔记
- newLife
- 解决ViewPagerIndicator标题显示不全的问题
- hud 1505
- 沉淀式状态栏,将状态栏变成自己需要的颜色
- el 使用规则及案例
- Android消息推送完美解决方案全析