使项读取器返回列表,而不是单个对象-Spring Batch [英] Making a item reader to return a list instead single object - Spring batch
本文介绍了使项读取器返回列表,而不是单个对象-Spring Batch的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
问题是:如何让Spring Batch中的项阅读器传递列表,而不是单个对象。
我已经搜索过了,一些答案是修改项目读取器以返回对象列表,并将项目处理器更改为接受列表作为输入。
如何做项目阅读器/编写项目阅读器代码?
推荐答案
查看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
}
}
这篇关于使项读取器返回列表,而不是单个对象-Spring Batch的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文