这应该有所帮助:http://static.springsource.org/spring/docs/3.0.x/reference/jdbc.html#jdbc-advanced-jdbc
编辑:
final Long uid = 1L;
final List friendList /* = ... */;
int[] updateCounts = jdbcTemplate.batchUpdate(
"insert into fb_user_friends(fb_uid,friend_uid) values(?,?)",
new BatchPreparedStatementSetter() {
public void setValues(final PreparedStatement ps, final int i) throws SQLException {
ps.setLong(1, uid);
ps.setLong(2, friendList.get(i));
}
public int getBatchSize() {
return friendList.size();
}
});
要么
final List userList /* = ... */;
SqlParameterSource[] batch = SqlParameterSourceUtils.createBatch(userList.toArray());
int[] updateCounts = simpleJdbcTemplate.batchUpdate(
"insert into fb_user_friends(fb_uid,friend_uid) values(:uid,:friendUid)",
batch);
同
@Data // from lombok
class User {
private Long uid;
private Long friendUid;
}
未经测试,改编自提供的链接样本