springbatch对xml文件的读写数据操作

读数据:

@Configuration
public class ItemReaderXmlDemo {
    @Autowired
    private JobBuilderFactory jobBuilderFactory;
    @Autowired
    private StepBuilderFactory stepBuilderFactory;
    @Autowired
    private ItemReader xmlReader;

    @Bean
    public Job itemReaderXmlJob() throws ClassNotFoundException {
        return jobBuilderFactory.get("itemReaderXmlJob")
                .start(itemReaderXmlStep())
                .build();
    }

    public Step itemReaderXmlStep() throws ClassNotFoundException {
        return stepBuilderFactory.get("itemReaderXmlStep")
                .chunk(2)
                .reader(xmlReader)
                .writer(list -> {
                    for (Person person : list) {
                        System.out.println(person);
                    }
                }).build();
    }


}

写数据:

@Configuration
public class ItemWriteXmlDemo {
    @Autowired
    private JobBuilderFactory jobBuilderFactory;
    @Autowired
    private StepBuilderFactory stepBuilderFactory;
    @Autowired
    private ItemReader dbReader;
    @Autowired
    private ItemWriter xmlWrite;

    @Bean
    public Job itemWriteXmlJob() {
        return jobBuilderFactory.get("itemWriteXmlJob")
                .start(itemWriteXmlStep())
                .build();
    }

    @Bean
    public Step itemWriteXmlStep() {
        return stepBuilderFactory.get("itemWriteXmlStep")
                .chunk(1)
                .reader(dbReader)
                .writer(xmlWrite)
                .build();
    }
}

 

你可能感兴趣的:(spring,boot)