如何构造spring批处理多个读取器



我是springbatch用户中的新用户。下面的数据结构是一些示例结构。

用户表

| id | name| age|
| -------- | -------------- |-------------- |
| 1    | park            |12            |
| 2   | kim            |13|

user_service_history表

| id | user_id| status|
| -------- | -------------- |-------------- |
| 1    | 1            |create            |
| 2   | 1            |conenct|
| 3    | 1            |delete            |
| 4   | 2            |conenct|

弹簧批能做到这一点吗?我尝试了两步进阅读器,但春季批次只允许一步进阅读器…:(

Job{
step{
reader{
//this reader read to id and name
List<user> userList=select id , name from user
},
processor{/* do some process userList */},
writer{/* do nothing */}
},
step{
reader(List<user> userList){ // this parameter is delivered from above processor
//this reader read to user_service_history
select user_id,status from user_service_history joined user where in userList
}, 
processor{/* do some process */}
writer{/* final write wanted data */}
}
}

您不需要两个读卡器。你有几个选择:

  • 将单个读取器与连接两个表中数据的查询一起使用
  • 创建一个自定义读取器,根据需要从两个表中读取数据
  • 使用驱动查询模式,其中读取器从一个表读取项目,处理器从另一个表丰富这些项目。此处的项目将是用户

最新更新