Record splitting and grouping in spring batch

此生再无相见时 提交于 2019-12-12 02:58:36

问题


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:


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



来源:https://stackoverflow.com/questions/25199192/record-splitting-and-grouping-in-spring-batch

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!