spring - CompositeItemWriter 和 Wrapper
问题描述
- reader -> 注入一个名为 Person 的类
- processor -> injest Person,并返回一个包装对象,它有 3 个字段,它们都是 Person 类型(1. inputPerson,2. outputPerson,3. output)
- writer -> injest 这个包装器,应该将前两个字段写入一个文件中,第三个字段作为 xml 写入第二个文件中。
那就是我为这个问题编写的代码:
@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)。任何想法,我该怎么做?(如果可能的话,举个例子)
解决方案
推荐阅读
- c# - Sonarcube 不喜欢我的可序列化异常类的实现
- ios - Ionic Capacitor Deploy App on ios 13.3 device freeze splashscreen
- flutter - Flutter 从服务返回解析动态对象
- python - 如何将时间分成 10 分钟间隔并使用 Python 将其作为单独的列
- flutter - flutter - 在日历插件中制作动态标记事件
- php - 如何获取wiki pageid?
- javascript - 使用 Javascript 中的新查询解析服务器更新实时查询订阅
- c++ - 不同/较旧的处理器是否以不同的方式运行 c++ 代码?
- linux - 为什么Linux内核的arm端口在上下文切换时没有备份“cpsr”寄存器?
- javascript - Npm ES 模块包不适用于 Express / Babel