如何在FlatFileItemWriter中动态编写标题

时间:2019-06-07 11:31:53

标签: spring spring-boot spring-batch

无法在FlatFileItemWriter中动态创建列标题。

我正在创建一个将写入csv文件的批处理,处理器的输出是Map,

我正在将writer头配置为基于map(keys)是动态的,但是似乎我找不到其他方法来执行此操作。 TIA。

@Bean
@StepScope
public FlatFileItemWriter<Map> applicationWriter(
  @Value("#{jobParameters[filPath]}") String file)  {
FlatFileItemWriter<Map> writer = new FlatFileItemWriter<>();
writer.setResource(new FileSystemResource(file));
writer.setHeaderCallback(writer1 -> writer1.write("dynamic header from Map keys")); 
writer.setLineAggregator(new DelimitedLineAggregator<Map>() {{
  setDelimiter(",");
  setFieldExtractor(new BeanWrapperFieldExtractor<GenericFormEntity>() {{
    setNames(new String[]{"",""}); // <-- this should contain map keys
  }});
}});
return writer;

}

0 个答案:

没有答案