Making a item reader to return a list instead single object - Spring batch

泄露秘密 提交于 2019-11-30 22:35:49
Michael Pralow

take a look at the 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
   }
}

the processor works the same

public class FooProcessor implements ItemProcessor<List<?>, List<?>> {

    @Override
    public List<?> process(List<?> item) throws Exception {
        // ... logic
    }

}

instead of returning a list, the processor can return anything e.g. a String

public class FooProcessor implements ItemProcessor<List<?>, String> {

    @Override
    public String process(List<?> item) throws Exception {
        // ... logic
    }

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