【问题标题】:Making a item reader to return a list instead single object - Spring batch使项目阅读器返回列表而不是单个对象 - Spring批处理
【发布时间】:2012-08-09 09:46:17
【问题描述】:

问题是:如何在春季批次中使 Item reader 交付一个列表而不是单个对象。

我已经搜索过了,一些答案是修改项目阅读器以返回对象列表并更改项目处理器以接受列表作为输入。

如何做/编码项目阅读器?

【问题讨论】:

    标签: spring-batch


    【解决方案1】:

    看看official spring batch documentation for itemReader

    public interface ItemReader<T> {
    
        T read() throws Exception, UnexpectedInputException, ParseException;
    
    }
    // so it is as easy as
    public class ReturnsListReader implements ItemReader<List<?>> {
       public List<?> read() throws Exception {
          // ... reader logic
       }
    }
    

    处理器工作原理相同

    public class FooProcessor implements ItemProcessor<List<?>, List<?>> {
    
        @Override
        public List<?> process(List<?> item) throws Exception {
            // ... logic
        }
    
    }
    

    处理器可以返回任何东西,而不是返回一个列表,例如一个字符串

    public class FooProcessor implements ItemProcessor<List<?>, String> {
    
        @Override
        public String process(List<?> item) throws Exception {
            // ... logic
        }
    
    }
    

    【讨论】:

    • 我已更新过时的链接。另外,我有一个使用JdbcPagingItemReader 的工作代码,我可以调整它以返回对象的List 吗?请see my question
    • 它看起来不可能让它工作只是“调整”,我建议你根据你的要求在 stackoverflow 上创建一个完整的问题
    猜你喜欢
    • 2017-05-11
    • 1970-01-01
    • 1970-01-01
    • 2022-09-26
    • 1970-01-01
    • 1970-01-01
    • 2020-07-13
    • 2020-07-17
    • 1970-01-01
    相关资源
    最近更新 更多