其中statementName为sql文件ID,list为参数集合
// 批量删除
public void batchDelete(final String statementName, final List list) throws Exception{
if (list != null) {
this.getSqlMapClientTemplate().execute(new SqlMapClientCallback() {
public Object doInSqlMapClient(SqlMapExecutor executor) throws SQLException {
executor.startBatch();
for (int i = 0, n = list.size(); i < n; i++) {
executor.delete(statementName, list.get(i));
}
executor.executeBatch();
return null;
}
});
}
}
// 批量修改
public void batchUpdate(final String statementName, final List list) throws Exception{
if (list != null) {
this.getSqlMapClientTemplate().execute(new SqlMapClientCallback() {
public Object doInSqlMapClient(SqlMapExecutor executor) throws SQLException {
executor.startBatch();
for (int i = 0, n = list.size(); i < n; i++) {
executor.update(statementName, list.get(i));
}
executor.executeBatch();
return null;
}
});
}
}
// 批量添加
public void batchInsert(final String statementName, final List list) throws Exception{
if (list != null) {
this.getSqlMapClientTemplate().execute(new SqlMapClientCallback() {
public Object doInSqlMapClient(SqlMapExecutor executor) throws SQLException {
executor.startBatch();
for (int i = 0, n = list.size(); i < n; i++) {
executor.insert(statementName, list.get(i));
}
executor.executeBatch();
return null;
}
});
}
}
原帖地址:http://blog.csdn.net/xinghui_liu/article/details/7230400