Record splitting and grouping in spring batch

2019-08-28 23:44发布

I have a requirement to split my input file which contains records of different length and type some beans. I am able to map each record to different bean using CompositeItemReader. But there is some parent-child relation exists between these records. I want to form a bean which contains child beans. Any help is appreciated.

This is my sample input file.

AB,01,05,HHGFG,05 CD,452,63,FDD,07,54,76,EQWED PT,GGG,76,YYY CD,08,06,ASW,97,55,66,BT AB,96,87,KKK,03 PT,TIPWQ,19,YEQ PT,ROPRG,39,PRVM

CD,08,06,ASW,97,55,66,BT

Here AB is considered as parent record. My segments start with AB*, CD*, PT*

1条回答
时光不老,我们不散
2楼-- · 2019-08-29 00:28

Top level domain object creation is responsability of ItemReader so this type of aggregation should be done in reading phase.
In SB-sample-projects there is a multilineOrder sample where you have a skeleton about how to resolve this type of problem; of course you have to resolve "manually" parent/child relationship between objects and manage errors during read.
Another example at Spring Batch :Aggregated reader / writer Issue

查看更多
登录 后发表回答