Spring Batch - Write multiple files based on records count

早过忘川 提交于 2019-12-13 04:56:29

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!