Spring batch read multiline once in the reader using AggregateItemReader or other solution
我使用Spring Batch处理具有300万行数据的文件。
该文件的结构如下:
1 2 3 4 5 6 7 | ID1-Adress1-NumberPhone1 ID1-Adress2-NumberPhone2 ID1-Adress3-NumberPhone3 ID2-Adress1-NumberPhone1 ID2-Adress2-NumberPhone2 ID3-Adress1 NumberPhone1 ... |
我需要按ID读取文件,
不是逐行。
例如:
读取
1 2 3 4 | ID1-Adress2-NumberPhone2 ID1-Adress3-NumberPhone3 ID2-Adress1-NumberPhone1 ID2-Adress2-NumberPhone2 |
然后创建一个Person对象,该对象具有ID和一个作为属性
将此对象传递给处理器,
然后读取与第二个ID相关的行,
以此类推,直到我有一个Person对象列表提供给作者。
具体来说,
在将每个多行对象发送到处理器之前,在将其存储在数据库中之前,我需要我的阅读器完成它。
我遵循的过程创建了一个步骤,该步骤逐行读取然后将该行作为对象传递给编写器,在此编写器中,我循环查找具有相同ID的对象,并将它们映射(写入)到另一个对象中是我的完整对象,然后执行此最终对象的最终列表的第二步将其读取并将其插入数据库中,问题在于,第一步需要花费比2H更多的时间
阅读器中是否有一种方法,一个聚合过程?我试图看到这个例子https://github.com/spring-projects/spring-batch/tree/master/spring-batch-samples/src/main/java/org/springframework/batch/sample/domain/ multiline但我根本不明白我需要一个简单的具体示例来适应上面引用的文件格式
您可以看一下多行示例。在此示例中,输入文件具有以下格式(与您的情况类似):
1 2 3 4 5 6 7 8 9 | BEGIN INFO,UK21341EAH45,customer1 AMNT,978,98.34 END BEGIN INFO,UK21341EAH46,customer2 AMNT,112,18.12 END ... |
自定义阅读器用于汇总跨越多行的项目。在此示例中,(逻辑)项由
希望这会有所帮助。