iBATIS批量操作

简介:

  

其中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

 

 

目录
相关文章
|
SQL Java
SpringData JPA多表关联操作
SpringData JPA多表关联操作
115 0
|
SQL Java 数据库连接
MyBatis 如何执行批量操作?
MyBatis 如何执行批量操作?
71 0
|
SQL Java 数据库连接
Apache-DBUtils实现CRUD操作
Apache-DBUtils实现CRUD操作
Apache-DBUtils实现CRUD操作
|
SQL 存储 关系型数据库
EFCore批量操作,你真的清楚吗
EntityFramework Core有许多新的特性,其中一个重要特性便是批量操作。批量操作意味着不需要为每次Insert/Update/Delete操作发送单独的命令,而是在一次SQL请求中发送批量组合指令。
EFCore批量操作,你真的清楚吗
|
SQL XML 关系型数据库
Ibatis批量删除的xml
Ibatis批量删除的xml 代码如下。
343 0
|
JavaScript Java 数据库连接
使用 hibernate 进行 批量删除
使用 hibernate 进行 批量删除
118 0
|
SQL Java 数据库连接
Mybatis批量更新,批量删除
Mybatis批量更新,批量删除
1667 0
Mybatis批量更新,批量删除