如何在春季批量编写自定义项目阅读器

时间:2014-01-09 05:56:27

标签: spring spring-batch

我是Spring批处理的新手,我需要在Spring批处理中自定义ItemReaders。我怎样才能做到这一点?我的要求是我有来自多个源系统的源,这些源存储在不同的临时表中。现在基于源系统,我必须查询相应的临时表。为此,我需要编写一个自定义ItemReader。任何人都可以帮助我。

2 个答案:

答案 0 :(得分:1)

试试这个:

import org.springframework.batch.item.ItemReader;
import org.springframework.batch.item.NonTransientResourceException;
import org.springframework.batch.item.ParseException;
import org.springframework.batch.item.UnexpectedInputException;


public class YoutItemReader implements ItemReader<YourObject> {

    @Override
    public YourObject read() throws Exception, UnexpectedInputException, ParseException, NonTransientResourceException {

        // You Code Here
        YourObject oa = new YourObject();
        return oa;
    }

}

答案 1 :(得分:0)

检查以下文档要点6.9

http://docs.spring.io/spring-batch/reference/html/readersAndWriters.html

你必须创建rowmapper并使用JdbcCursorItemReader或JdbcPagingItemReader,还有其他选项使用JPA和hibernate,如果你从不同的表中读取,你可以使视图连接所有这些表