这是我为解决此问题而编写的代码:
@Bean
public CompositeItemWriter<Wrapper> compositeItemWriter(){
CompositeItemWriter writer = new CompositeItemWriter();
writer.setDelegates(Arrays.asList(firstTwoWriters(), thirdWriter));
return writer;
}
@Bean
public StaxEventItemWriter<Wrapper> firstTwoWriters() {
StaxEventItemWriter<Wrapper> xmlFileWriter = new StaxEventItemWriter<>();
xmlFileWriter.setRootTagName("something");
String outputName = applicationArguments.getOptionValues("output").get(0);
FileSystemResource outputResource = new FileSystemResource(outputName);
xmlFileWriter.setResource(outputResource);
Jaxb2Marshaller personMarshaller = new Jaxb2Marshaller();
scoringMapMarshaller.setClassesToBeBound(Person.class);
xmlFileWriter.setMarshaller(personMarshaller );
}
问题是,我无法选择此编写器应使用哪个字段(inputPerson,outputPerson或output)(应将哪个字段转换为xml)。 有什么想法,我该怎么做? (如果可能,举个例子)