gpt4 book ai didi

java - 如何使用 Spring Batch 读取简单的 xml 列表?

转载 作者:行者123 更新时间:2023-11-30 03:50:23 24 4
gpt4 key购买 nike

<parent>
<child>aaa</child> <!-- simple string -->
<child>bbb</child>
...
</parent>

我如何使用以下处理器读取这些 child 的值和处理?

@Override
public void write(final List<? extends String> children) {
}

请注意,我没有任何计划来将绑定(bind)类映射到 <parent/> .

最佳答案

child 设为片段根元素,并将其值映射为 java.lang.String

<bean name="reader" class="org.springframework.batch.item.xml.StaxEventItemReader">
<property name="fragmentRootElementName" value="child" />
<property name="resource" value="classpath:/xmlStringReader/source.xml" />
<property name="unmarshaller" ref="unmarshaller" />
</bean>
<bean name="unmarshaller" class="org.springframework.oxm.xstream.XStreamMarshaller">
<property name="aliases">
<map>
<entry key="child" value="java.lang.String" />
</map>
</property>
</bean>

关于java - 如何使用 Spring Batch 读取简单的 xml 列表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24612114/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com