ItemReader for records returned by CrudRepository

情到浓时终转凉″ 提交于 2019-12-13 04:26:31

问题


I have a spring batch application wherein reader reads from an external db and processor transforms it to the POJO of my destination db , writer will write the transformed POJO to the destination db

I am using following CrudRepository

public interface MyCrudRepository extends CrudRepository<MyDbEntity, String> {

    List<MyDbEntity> findByPIdBetween(String from, String to);

    List<MyDbEntity> findByPIdGreaterThan(String from);  
}

I wanted to know , how the ItemReader for above would look like?

Should I call myCrudRepository.findByPidBetween(String from, String to) in @PostConstruct of my ItemReader ?

Wouldnt that make the ItemReader static? As each job run would have different method parameter for findByPidBetween.

How should ItemReader be structured for above problem?


回答1:


I wanted to know , how the ItemReader for above would look like?

RepositoryItemReader is what you need. You can use it with your repository and specify the method to use to read items. You can find an example here

each job run would have different method parameter for findByPidBetween

You can pass those as parameters to your job and use them in your reader.



来源:https://stackoverflow.com/questions/53117650/itemreader-for-records-returned-by-crudrepository

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