iBATIS批量操作-阿里云开发者社区

开发者社区> 数据库> 正文

iBATIS批量操作

简介:    其中statementName为sql文件ID,list为参数集合     //  批量删除 public void batchDelete(final String statementName, final List list) throws Exception{        if (list != null) {                this.getS

  

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

 

 

版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。

分享:
数据库
使用钉钉扫一扫加入圈子
+ 订阅

分享数据库前沿,解构实战干货,推动数据库技术变革

其他文章