首先批量更新 插入数据要放到一个事务里面,这也是配出来的,源码
<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;
}
});
}