Spring Batch - Using an ItemWriter with List of Lists

后端 未结 2 1835
伪装坚强ぢ
伪装坚强ぢ 2020-11-27 06:36

Our processor returns a List (effectively passing a List>) to our ItemWriter.

Now, we observed t

2条回答
  •  清歌不尽
    2020-11-27 07:10

    public class ListUnpackingItemWriter implements FlatFileItemWriter>, ItemStream, InitializingBean {
    
        @Override
        public void afterPropertiesSet() {
            setLineAggregator(item -> String.join("\n", item.stream().map(T::toString).collect(Collectors.toList())));
        }
    
    }
    

    Just added a custom line aggregator to the above solution, this helps in writing the content to a file by using FlatFileItemWriter>. You can replace T with actual class name to avoid compilation error while calling toString() method.

提交回复
热议问题