Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在编写一个春季批处理作业,其中我正在从数据库中读取 ItemReader 并在处理器中应用一些规则并希望在 ItemWriter 中更新。
我无法弄清楚如何在 ItemWriter 类中执行更新操作。
我尝试使用更新语句设置数据源,但我不知道如何在此处传递主键来更新记录
您可以使用ItemPreparedStatementSetter. 这是一个例子:
ItemPreparedStatementSetter
https://github.com/spring-projects/spring-batch/blob/master/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/builder/JdbcBatchItemWriterBuilderTests.java#L148- L166
您也可以使用“更新”SQL 语句:
https://github.com/spring-projects/spring-batch/blob/master/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/builder/JdbcBatchItemWriterBuilderTests.java#L135