ibatis的批量存储
public void saveItemBatch(final List<Item> itemList, final Long catalogId) {
this.getSqlMapClientTemplate().execute(new SqlMapClientCallback() {
public Object doInSqlMapClient(SqlMapExecutor executor)
throws SQLException {
executor.startBatch();
int batch = 0;
for (Item item : itemList) {
Long itemId = getId();
item.setId(itemId);
executor.insert(save, item);
Map<String, Object> map = new HashMap<String, Object>();
map.put("catalog_id", catalogId);
map.put("item_id", itemId);
map.put("score", 0);
executor.insert(saveCatalogItemLink, map);
batch++;
if (batch == 1000) {
executor.executeBatch();
batch = 0;
}
}
return executor.executeBatch();
}
});
}