Read one record/item and write multiple records/items using spring batch

前端 未结 3 2092
轻奢々
轻奢々 2020-12-10 04:25

I did some searching but couldn\'t find any sample/example.

I\'ve a requirement where geo coordinates from one table (input) are read, processed to generate POI\'s a

3条回答
  •  囚心锁ツ
    2020-12-10 05:12

    if you just want to spread the items to different writers (read duplicate output) you can use the existing CompositeItemWriter

    but i'm not sure if your processor will produce different item types or if you want to spread the content of one complex item type to multiple writers, for those cases you can use a slightly changed version for a multiline-record-writer question

    public class MultiOutputItemWriter implements ItemWriter {
    
    private JdbcBatchItemWriter delegateFoo;
    private JdbcBatchItemWriter delegateBar;
    
    public void write(List items) throws Exception {
           // if you have different types of items
           // check Object Class
           // add to new List
           // call delegate e.g. delegateFoo.write(List with ClassFoo);
           //
           // or if you have complex objects
           // same procedure as above, but with
           // add to new List with item.getClassFoo
     }
    }
    
    
    

    if you use FlatFileItemWriter, do not forget to register the delegates as ItemStreams (so spring batch will open/close them for you)

    提交回复
    热议问题