我有一个Spring批处理项目来创建xml文件,它返回:
<UNITS>
<pojo.unitgen>
<event>Z_RECEIVING_RESULT</event>
<type>Receipt</type>
<internalDeviceId>6</internalDeviceId>
<imei>990000223446789</imei>
</pojo.unitgen>
<pojo.unitgen>
<event>Z_RECEIVING_RESULT</event>
<type>Receipt</type>
<internalDeviceId>2</internalDeviceId>
<imei>992000123456789</imei>
</pojo.unitgen>
</UNITS>
我如何更改'unit'的标签'pojo.unitgen'
这是我的ItemWriter:
<!-- write extracted Receiving data into a xml file -->
<bean id="iwReceiving" class="org.springframework.batch.item.xml.StaxEventItemWriter"
scope="step">
<property name="resource" value="file:${Report.pathToSave}${Report.fileName}" />
<property name="marshaller" ref="UnitMarshaller" />
<property name="rootTagName" value="UNITS" />
</bean>
<bean id="UnitMarshaller" class="org.springframework.oxm.xstream.XStreamMarshaller">
<property name="autodetectAnnotations" value="true"/>
</bean>
答案 0 :(得分:1)
我假设你在“pojo”包中有一个“UnitGen”类,对吧? 尝试使用注释“@XStreamAlias”:
package pojo;
@XStreamAlias("unit")
public class UnitGen {
...
}
您可能需要设置带注释的类:
<bean id="UnitMarshaller" class="org.springframework.oxm.xstream.XStreamMarshaller">
<property name="autodetectAnnotations" value="true"/>
<property name="annotatedClasses">
<list>
<value>pojo.UnitGen</value>
</list>
</property>
</bean>