ibatis 的批量插入 批量更新数据

首先批量更新 插入数据要放到一个事务里面,这也是配出来的,源码

 

    
 <bean id="transactionManager"
  class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
  <property name="dataSource" ref="dataSource" />
 </bean>
 
 <aop:config>
  <aop:advisor pointcut="execution(* *..business..*(..))"
   advice-ref="txAdvice" />
 </aop:config>
 <tx:advice id="txAdvice" transaction-manager="transactionManager">
  <tx:attributes>
   <tx:method name="New*" />
   <tx:method name="Edit*" />
   <tx:method name="Del*" />
   <tx:method name="new*" />
   <tx:method name="edit*" />
   <tx:method name="del*" />
   <tx:method name="insert*" />
   <tx:method name="Insert*" />
   <tx:method name="update*" />
   <tx:method name="GetProcList*" />
   <tx:method name="Update*" />
   <tx:method name="charge*" /> 
   <tx:method name="GetProcList*" />
   
   <tx:method name="audit*" /> 
   <tx:method name="bus*" /> 
   <tx:method name="Audit*" />
   <tx:method name="regist*" />
   <tx:method name="reg*" /> 
   <tx:method name="Upt*" />
   <tx:method name="Window*" />
   <tx:method name="subtract*" />
   
   <tx:method name="Check*" />
   <tx:method name="check*" />
   <tx:method name="Save*" />
   <tx:method name="Out*" />
   <tx:method name="Return*" />
   <tx:method name="com*" />
   <tx:method name="exec*" />
   <tx:method name="query*" />
   
   <tx:method name="pro*" />
   <tx:method name="allow*" />
   <tx:method name="upload*" />
   <tx:method name="Upload*" />
   <tx:method name="reAudit*" />
   
   <tx:method name="confirm*" />
   <tx:method name="arrange*" />
   <tx:method name="apply*" />
   <tx:method name="prescrip*" />
   <tx:method name="rePrescrip*" />
   
   <tx:method name="exist*" />
   <tx:method name="is*" />
   <tx:method name="grant*" />
   <tx:method name="unGrant*" />
   <tx:method name="init*" />
   
   <tx:method name="day*" />
   <tx:method name="all*" />
   
   <tx:method name="notrans*" propagation="NEVER" />
   <tx:method name="*" read-only="true" />
  </tx:attributes>
 </tx:advice>
 

只要在包

business下面的  方法名字以 上面这些开头的 都配成事务了,对数据库的操作会,整体的提交,如果其中一条数据错误,就回滚,

第2,DAO层  这样写   会逐条更新,然后整体提交

 

 

public void updateACPHzRjpgList(final List<HashMap> cphzrjpglist) {
  this.getSqlMapClientTemplate().execute(new SqlMapClientCallback() {
   public Object doInSqlMapClient(SqlMapExecutor executor) throws SQLException {
    executor.startBatch();
    for (Map cphzrjpg:cphzrjpglist) {
     executor.insert("HIS_CPINF.updateACPHzRjpgList", cphzrjpg);
    } 
    executor.executeBatch();
    return null;
   }
  });
 }

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值