Spring Batch-FlatFileReader中是否可能有动态列? [英] Spring Batch - Is it possible to have a dynamic column in FlatFileReader?

查看:173
本文介绍了Spring Batch-FlatFileReader中是否可能有动态列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在处理许多没有固定标题/列的CSV文件,说我可以获得10列的file1.csv和50列的file2.csv.

I'm dealing with many CSVs files that don't have a fixed header/column, saying that I can get file1.csv with 10 column and file2.csv with 50 column.

我无法预先知道将要拥有的列数,无法为每种文件类型创建特定的作业,我的输入将是一个黑匣子:一堆CSV档案,其X数列数从10到无限.

I can't know in advance the number of column that I'll have, I can't create a specific job for each file type, my input will be a black box: bunch of CSV that will have an X number of column from 10 to infinite.

由于我想使用Spring Batch自动导入这些CSV,因此我想知道是否可行?我知道我必须获得固定数目的列,这是因为存在处理器,而且我需要在将数据发送回写程序之前将我的数据序列化为POJO.

As I want to use Spring Batch to auto import these CSVs, I want to know if it is possible? I know that I have to get a fixed number of column because of the processor and the fact that I need to serialize my data into a POJO before sending it back to a writer.

我的处理器可以序列化一个阵列吗?除了发送一个简单的对象外,我还能得到一个对象数组吗?在工作结束时,我会得到一个对象数组吗?

Could my processor serialize an Array? beside sending one simple Object, can I get an Array of Object and in the end of my job I'll will have an Array of an Array of Object?

您怎么看?

谢谢

推荐答案

创建您自己的LineTokenizer实现. DelimitedLineTokenizer需要预定义的列数.如果您创建自己的,则可以根据需要进行动态调整.您可以在以下文档中阅读有关LineTokenizer的更多信息:

Create your own LineTokenizer implementation. The DelimitedLineTokenizer expects a predefined number of columns. If you create your own, you can be as dynamic as you want. You can read more about the LineTokenizer in the documentation here: http://docs.spring.io/spring-batch/apidocs/org/springframework/batch/item/file/transform/LineTokenizer.html

这篇关于Spring Batch-FlatFileReader中是否可能有动态列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆