jdbcTemplate.batchUpdate问题
如何将其转换为返回jdbcTemplate.batchUpdate?jdbcTemplate.batchUpdate问题
它需要执行到几个表。
@Override public int delete(int id) {
String sql = "update user set deleted=1 where user_id = ?";
Object[] params = new Object[] { id };
try {
return jdbcTemplate.update(sql, params);
} catch (IncorrectResultSizeDataAccessException e) {
throw new UserNotFoundException("User.not.found");
}
}
回答:
@Override public void delete(List<Integer> ids) {
String sql = "update user set deleted=1 where user_id = ?";
jdbcTemplate.batchUpdate(sql, new BatchPreparedStatementSetter() {
@Override
public void setValues(PreparedStatement ps, int i) throws SQLException {
Integer userId = ids.get(i);
ps.setLong(1, userId);
}
@Override
public int getBatchSize() {
return ids.size();
}
});
}
以上是 jdbcTemplate.batchUpdate问题 的全部内容, 来源链接: utcz.com/qa/263594.html