加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-16 08:15:51 所属栏目:百科 来源:网络整理
导读:JAXB绑定编译器将W3C XML模式转换为一个或多个Java类, jaxb.properties 文件以及可能的一些资源文件。 JAXB还提供了一种从注释Java类生成模式的方法。 Spring支持JAXB 2.0 API作为XML编组策略,遵循第21.2节“Marshaller和Unmarshaller”中描述的 Marshalle

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读