May 2015
Intermediate to advanced
234 pages
4h 18m
English
Write a CSV file as part of a read/process/write step.
We will generate a CSV file from User objects. Make sure that the User class exists:
public class User {
private String firstName;
private int age;Use FlatFileItemWriter provided by Spring Batch:
writer() method that will get the fields of a User object, build a comma-separated line with them, and write the line to a CSV file:@Bean @StepScope public FlatFileItemWriter<User> writer(@Value("#{jobParameters[fileOut]}") String csvFilePath) { BeanWrapperFieldExtractor<User> fieldExtractor = new BeanWrapperFieldExtractor<User>(); fieldExtractor.setNames(new String[]{"firstName","age"}); DelimitedLineAggregator<User> lineAggregator = new DelimitedLineAggregator<User>(); ...Read now
Unlock full access