Part V. 数据访问-21. 使用O/X Mappers编组XML-21.5 JAXB

JAXB绑定编译器将W3C XML模式转换为一个或多个java类jaxb.properties文件以及可能的一些资源文件。 JAXB还提供了一种从注释java类生成模式的方法

Spring支持JAXB 2.0 API作为XML编组策略,遵循第21.2节“Marshaller和Unmarshaller”中描述的MarshallerUnmarshaller接口。 相应的集成类驻留在org.springframework.oxm.jaxb包中。

21.5.1 Jaxb2Marshaller

Jaxb2Marshaller类实现了SpringUnmarshaller接口。 它需要一个上下文路径来操作,您可以使用contextpath属性进行设置。 上下文路径是包含模式派生类的冒号(:)分离的Java包名称的列表。 它还提供了一个classesToBeBound属性,它允许您设置要由编组器支持的类的数组。 通过向bean指定一个或多个模式资源来执行模式验证,如下所示:

<beans>
<bean id="jaxb2Marshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
<property name="classesToBeBound">
<list>
<value>org.springframework.oxm.jaxb.Flight</value>
<value>org.springframework.oxm.jaxb.Flights</value>
</list>
</property>
<property name="schema" value="classpath:org/springframework/oxm/schema.xsd"/>
</bean>

...

</beans>

基于XML Schema的配置

jaxb2-marshaller标签配置了一个org.springframework.oxm.jaxb.Jaxb2Marshaller。 这是一个例子:

<oxm:jaxb2-marshaller id="marshaller" contextpath="org.springframework.ws.samples.airline.schema"/>

或者,可以通过待绑定的子标签将绑定的类列表提供给编组者:

"marshaller">
<oxm:class-to-be-bound name="org.springframework.ws.samples.airline.schema.Airport"/>
<oxm:class-to-be-bound name="org.springframework.ws.samples.airline.schema.Flight"/>
...
</oxm:jaxb2-marshaller>

可用属性有:

Attribute Description required
id the id of the marshaller no
contextpath the JAXB Context path no

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


php输出xml格式字符串
J2ME Mobile 3D入门教程系列文章之一
XML轻松学习手册
XML入门的常见问题(一)
XML入门的常见问题(三)
XML轻松学习手册(2)XML概念
xml文件介绍及使用
xml编程(一)-xml语法
XML文件结构和基本语法
第2章 包装类
XML入门的常见问题(二)
Java对象的强、软、弱和虚引用
JS解析XML文件和XML字符串详解
java中枚举的详细使用介绍
了解Xml格式
XML入门的常见问题(四)
深入SQLite多线程的使用总结详解
PlayFramework完整实现一个APP(一)
XML和YAML的使用方法
XML轻松学习总节篇