我正在尝试使用FlatFileItemReader解析CSV文件。该CSV包含一些带引号的换行符,如下所示。
email, name
[email protected], "NEW NAME
ABC"
但是此解析失败,必填字段为2,而实际字段为1。
FlatFileReader配置中缺少什么?
<property name="lineMapper">
<bean class="org.springframework.batch.item.file.mapping.DefaultLineMapper">
<!-- The lineTokenizer divides individual lines up into units of work -->
<property name="lineTokenizer">
<bean
class="org.springframework.batch.item.file.transform.DelimitedLineTokenizer">
<!-- Names of the CSV columns -->
<property name="names"
value="email,name" />
</bean>
</property>
<!-- The fieldSetMapper maps a line in the file to a Product object -->
<property name="fieldSetMapper">
<bean
class="com.abc.testme.batchjobs.util.CustomerFieldSetMapper" />
</property>
</bean>
</property>
最佳答案
开箱即用的FlatFileItemReader为您的用例使用SimpleRecordSeparatorPolicy
您需要设置DefaultRecordSeparatorPolicy
从其javadoc引用:
xml配置示例
<bean id="reader"
class="org.springframework.batch.item.file.FlatFileItemReader">
...
<property name="recordSeparatorPolicy">
<bean class="org.springframework.batch.item.file.separator.DefaultRecordSeparatorPolicy" />
</property>
...
</bean>