Spring Batch How to read multiple table (queries) as Reader and write it as flat file write(Spring Batch如何作为Reader读取多个表(查询)并将其作为平面文件写入)
本文介绍了Spring Batch如何作为Reader读取多个表(查询)并将其作为平面文件写入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的项目中,我读取了具有不同查询的多个表,并将这些结果集合并到平面文件中。我怎样才能做到这一点。我的意思是JdbcReader直接接受1个SELECT查询,我如何自定义它。
推荐答案
如果JdbcCursorItemReader不符合您的需要,您始终可以通过实现ItemReader接口自由实现自定义读取器。
public interface ItemReader<T> {
T read() throws Exception, UnexpectedInputException, ParseException;
}
只需编写实现此接口的类并插入jdbcTemplate即可查询多个表。
public Class MyCompositeJdbcReader implements ItemReader<ConsolidateResult>{
private JdbcTemplate jdbcTemplate;
public ConsolidateResult read()
throws Exception, UnexpectedInputException, ParseException{
ConsolidateResult cr = new ConsolidateResult();
String name= this.jdbcTemplate.queryForObject(
"select name from customer where id = ?",new Object[]{1}, String.class);
String phoneNumber= this.jdbcTemplate.queryForObject(
"select phone from customer_contact where custid = ?",
new Object[]{1},String.class);
cr.setName(name);
cr.setPhone(phoneNumber);
return cr;
}
}
我没有编译代码,但我希望它能提供一些启示。
这篇关于Spring Batch如何作为Reader读取多个表(查询)并将其作为平面文件写入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
沃梦达教程
本文标题为:Spring Batch如何作为Reader读取多个表(查询)并将其作为平面文件写入
基础教程推荐
猜你喜欢
- 如何强制对超级方法进行多态调用? 2022-01-01
- Java 中保存最后 N 个元素的大小受限队列 2022-01-01
- 首次使用 Hadoop,MapReduce Job 不运行 Reduce Phase 2022-01-01
- Spring Boot Freemarker从2.2.0升级失败 2022-01-01
- 如何使用 Eclipse 检查调试符号状态? 2022-01-01
- 如何使用 Stream 在集合中拆分奇数和偶数以及两者的总和 2022-01-01
- 如何在不安装整个 WTP 包的情况下将 Tomcat 8 添加到 Eclipse Kepler 2022-01-01
- 如何对 HashSet 进行排序? 2022-01-01
- 在螺旋中写一个字符串 2022-01-01
- 由于对所需库 rt.jar 的限制,对类的访问限制? 2022-01-01