英文:
How to pass data into spring batch ItemProcessor?
问题
我有一个包含数据记录(案例)的CSV文件,我创建了一个caseDTO
对象来存储这些数据。然而,caseDTO
的一些属性必须从文件名中包含的数据中提取(每个文件的名称都必须具有严格的结构,包含一些数据)。
我想要实现的目标是将文件名中包含的数据传递给项目处理器(item processor),在将其传递给项目写入器(item writer)之前,将此数据追加到每个caseDTO
中。
是否有人知道如何在从控制器启动作业时将数据传递给步骤中的itemProcessor
?
提前感谢。
英文:
I have a CSV file that contains records of data (cases), for which I created a caseDTO
object , however some of the properties of the caseDTO
must be field from data included in the file name (every file must has a name with strict structure that contains some data).
What i want to achieve is to pass the data included in the file name to the item processor where i will append this data into every caseDTO
before passing it to the item writer.
Does any one knows how to pass data to a step itemProcessor
when I launch the job from the controller?
Thanks in advance.
答案1
得分: 0
最简单的解决方案是将动态参数设置在作业参数中,这样步骤的写入器、处理器和读取器就可以访问它们。通过以下方式将它们的值注入:
@Value("#{jobParameters['fileName']}")
public void setFileName(final String name) {
//...
}
英文:
the simplest solution is to set the dynamic parameters in the job parameters so the step's writer , processor , reader can have access to it . by injecting their values as following
@Value("#{jobParameters['fileName']}")
public void setFileName(final String name) {
//...
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论