我正在使用Spring批。如何更新单个数据库调用中的所有记录?
@Autowired
private JdbcTemplate jdbcTemplate;
@Override
public void write(List<? extends Users> users) throws Exception {
String updateQuery = "update users set ddp_created_fl=? where email=?";
for(Users user:users) {
jdbcTemplate.update(updateQuery, 1, user.getEmail());
}
}发布于 2020-01-31 16:21:08
可以使用batchUpdate更新单个数据库调用中的所有记录。
public void write(List<Users> users) throws Exception {
String updateQuery = "update users set ddp_created_fl=? where email=?";
jdbcTemplate.batchUpdate(updateQuery,
new BatchPreparedStatementSetter() {
public void setValues(PreparedStatement ps, int i)
throws SQLException {
ps.setLong(1, 1);
ps.setString(2, users.get(i).getEmail());
}
public int getBatchSize() {
return users.size();
}
});
}https://stackoverflow.com/questions/60005517
复制相似问题