您的位置:首页 > 其它

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

2012-11-30 09:48 471 查看
首先批量更新 插入数据要放到一个事务里面,这也是配出来的,源码

<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;

}

});

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: