java如何在spring batch中的单个条目读取器中读取逗号分隔和管道分隔的csv文件
我对sprig batch是新手。 我有一个包含多个csv文件的文件夹,我实现了MultiResourceItemReader()来读取这些文件。只有当所有csv文件都以管道(|)分隔时,它才起作用
我想使用单个读卡器读取逗号(“,”)分隔的csv和管道分隔的csv。可能吗?如果是,怎么做
这是我的密码
@Bean
@StepScope
public MultiResourceItemReader<Person> multiResourceItemReader(@Value("#{jobParameters[x]}") String x,@Value("#{jobParameters[y]}") String y,@Value("#{jobParameters[z]}") String z) {
Resource[] resourcessss = null;
ClassLoader cl = this.getClass().getClassLoader();
ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(cl);
try {
resourcessss = resolver.getResources("file:" + z);
}catch(Exception e) {
}
MultiResourceItemReader<Person> resourceItemReader = new MultiResourceItemReader<Person>();
resourceItemReader.setResources(resourcessss);
resourceItemReader.setDelegate(reader());
return resourceItemReader;
}
@Bean
public FlatFileItemReader<Person> reader() {
FlatFileItemReader<Person> reader = new FlatFileItemReader<Person>();
reader.setLineMapper(new DefaultLineMapper() {
{
setLineTokenizer(new DelimitedLineTokenizer() {
{
setNames(new String[]{"Id","postCode"});
}
{
setDelimiter("|");
}
});
setFieldSetMapper(new BeanWrapperFieldSetMapper<Person>() {
{
setTargetType(Person.class);
}
});
}
});
return reader;
}
共 (0) 个答案