0

我正在使用 Spring Batch 读取固定长度的平面文件,我想跳过空行和不正确的行以进行批处理。在下面的示例中,我还想跳过以字符“------”开头的行。

你能帮我举一个使用跳过策略或其他方式的例子吗?

我的文件:

---------------------------A---------------------------

AARON THIAGO LOPES                       3099234 100-11

AARON PAPA DA SILVA                      8610822 160-26

ABNER MENEZEZ SOUZA                      1494778 500-35

EDSON EDUARD MOZART                      1286664 500-34 


//Method that reads the file.

@Configuration
@EnableBatchProcessing
public class SpringBatchConfig {

    @Bean
    public Job job(JobBuilderFactory jobBuilderFactory,
                   StepBuilderFactory stepBuilderFactory,
                   ItemReader<Aluno> itemReader,
                   ItemWriter<Aluno> itemWriter){

        Step step = stepBuilderFactory.get("ETL-file-load")
                .<Aluno, Aluno>chunk(100)
                .reader(itemReader)
                .writer(itemWriter)
                .build();

        return jobBuilderFactory.get("ETL-Load")
                .incrementer(new RunIdIncrementer())
                .start(step)
                .build();
    }

    @Bean
    public FlatFileItemReader<Aluno> itemReader(@Value("${input}") Resource resource) {
        FlatFileItemReader<Aluno> flatFileItemReader = new FlatFileItemReader<>();
        flatFileItemReader.setResource(resource);
        flatFileItemReader.setName("CSV-Reader");
        flatFileItemReader.setLinesToSkip(2);
        flatFileItemReader.setLineMapper(lineMapper());
        return flatFileItemReader;
    }
4

0 回答 0