是关于JdbcTemplate批量操作方法的, 很少用, 备注一下!
public int[] batchUpdate(String jdbcTemplateId, String sql, final List<Map<String, String>> rows,
final List<String> columnNames, final Map<String, String> columnTypes) throws Exception {
JdbcTemplate jdbcTemplate = jdbcTemplates.get(jdbcTemplateId);
BatchPreparedStatementSetter pss = new BatchPreparedStatementSetter() {
public void setValues(PreparedStatement ps, int i) throws SQLException {
Map<String, String> row = rows.get(i);
if (DbUtils.isInvalidRow(row)) {
return;
}
int columnIndex = 0;
for (String columnName : columnNames) {
Object value = DbUtils.convertValue(row, columnName, columnTypes);
ps.setObject(++columnIndex, value);
}
}
public int getBatchSize() {
return rows.size();
}
};
return jdbcTemplate.batchUpdate(sql, pss);
}