我遵循这个tutorial,我得到FlatFileParseException错误:
org.springframework.batch.item.file.FlatFileParseException: Parsing
error at line: 1 in resource=[class path resource [country.csv]],
input=[AA,Aruba]
country.csv
AA,Aruba
BB,Baruba
这是我的ItemReader方法
@Bean
public ItemReader reader() {
FlatFileItemReader reader = new FlatFileItemReader();
reader.setResource(new ClassPathResource("country.csv"));
reader.setLineMapper(new DefaultLineMapper() {{
setLineTokenizer(new DelimitedLineTokenizer() {{
setNames(new String[] { "countryCode", "countryName" });
}});
setFieldSetMapper(new BeanWrapperFieldSetMapper() {{
setTargetType(Country.class);
}});
}});
return reader;
}
和Country.java
@Entity
@Table(name="Country")
public class Country {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id", nullable = false, updatable = false)
Long id;
@Column(name = "countryCode", nullable = false, updatable = false)
String countryCode;
@Column(name = "countryName", nullable = false, updatable = false)
String countryName;
public Country(String countryCode, String countryName) {
this.countryCode = countryCode;
this.countryName = countryName;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getCountryCode() {
return countryCode;
}
public void setCountryCode(String countryCode) {
this.countryCode = countryCode;
}
public String getCountryName() {
return countryName;
}
public void setCountryName(String countryName) {
this.countryName = countryName;
}
@Override
public String toString() {
return "countryCode: " + countryCode + ", countryName: " + countryName;
}
}