问题
In spring batch, I have an requirement to read from the database and to write in a file, The no of rows allowed in a file is N, so if N+10 records are fetched then two files should be created containing N rows and 10 rows respectively.
Can someone please help me with the writer implementation? Is there any other easy way of doing it? Thanks.
回答1:
Spring batch has MultiResourceItemWriter were you can write based on number of lines
<bean id="multiWriter"
class="org.springframework.batch.item.file.MultiResourceItemWriter">
<property name="delegate" ref="flatFileItemWriter" />
<property name="itemCountLimitPerResource" value="3" />
<property name="resource" value="file:c:/logs/te" />
</bean>
来源:https://stackoverflow.com/questions/30092149/spring-batch-write-multiple-files-based-on-records-count