[英]Spring Batch how to write a Map
我已经看过很多教程和弹簧材料,但我只找到了在 ItemWriter 中包含一个简单对象的示例。
例如...
@Bean
JdbcBatchItemWriter<Student> writer = new JdbcBatchItemWriter<>();
writer.setItemSqlParameterSourceProvider(new BeanPropertyItemSqlParameterSourceProvider<Student>());
writer.setItemPreparedStatementSetter(new ItemPreparedStatementSetter<Student>(){
@Override
public void setValues(Student student, PreparedStatement ps) throws SQLException {
ps.setLong(1,student.getStudentCode());
ps.setObject(2,student.getStudentGrade());
}});
writer.setSql(QUERY_STUDENT_GRADE_INSERT);
writer.setDataSource(dataSource);
return writer;
在我的实际场景中,我必须编写一个包含键和值的 Map,例如:
Map<KeyObject,Long>
但我不知道如何编写能够插入我在地图中收到的所有内容的代码。
还有一个问题...
当我处理一定数量的项目时,我需要将此数据存储在数据库中,但以前的内容仍保留在我的集合中,这样……我如何在写入后清理地图内容?
解决方案是将我的地图替换为列表
我只是使用 lambda 过滤列表中的对象并通过公共 itemWriter 写入它们。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.