public void create(List<Reply> replyList) { try { // 开始批处理 sqlMapClient.startBatch(); for (Reply reply: replyList) { // 插入操作 sqlMapClient.insert("Reply.create", reply); } // 执行批处理 sqlMapClient.executeBatch(); } catch (Exception e) { e.printStackTrace(); } }
public void create(List<Reply> replyList) { try { // 开始事务 sqlMapClient.startTransaction(); // 开始批处理 sqlMapClient.startBatch(); for (Reply reply: replyList) { // 插入操作 sqlMapClient.insert("Reply.create", reply); } // 执行批处理 sqlMapClient.executeBatch(); // 提交事务 sqlMapClient.commitTransaction(); } catch (Exception e) { e.printStackTrace(); } finally { try { // 结束事务 sqlMapClient.endTransaction(); } catch (SQLException e) { e.printStackTrace(); } } }
public void create(List<Reply> replyList) { if (!CollectionUtils.isEmpty(replyList)) { // 注意使用同一个SqlMapClient会话 SqlMapClient sqlMapClient = sqlMapClientTemplate.getSqlMapClient(); try { // 开始事务 sqlMapClient.startTransaction(); // 开始批处理 sqlMapClient.startBatch(); for (Reply reply : replyList) { // 插入操作 sqlMapClient.insert("Reply.create", reply); } // 执行批处理 sqlMapClient.executeBatch(); // 提交事务 交给Spring统一控制 // sqlMapClient.commitTransaction(); } catch (Exception e) { e.printStackTrace(); } finally { try { // 结束事务 sqlMapClient.endTransaction(); } catch (SQLException e) { e.printStackTrace(); } } } }
@SuppressWarnings("unchecked") public void create(final List<Reply> replyList) { // 执行回调 sqlMapClientTemplate.execute(new SqlMapClientCallback() { // 实现回调接口 public Object doInSqlMapClient(SqlMapExecutor executor) throws SQLException { // 开始批处理 executor.startBatch(); for (Reply reply : replyList) { // 插入操作 executor.insert("Reply.create", reply); } // 执行批处理 executor.executeBatch(); return null; } }); }
Copyright @ 飞飞 Powered by: .Text and ASP.NET Theme by: .NET Monster