ItemReader for records returned by CrudRepository

2019-08-27 22:29发布

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条回答
趁早两清
2楼-- · 2019-08-27 23:10

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.

查看更多
登录 后发表回答