网上有很多关于mybatis批量更新的例子,但基本都是针对mysql或oracle的,针对db2的少之又少;
一、oracle+mybatis执行批量更新:
mapper.xml:
<update id="doupdateBatchResUpStatusById" parameterType="java.util.List">
<foreach collection="list" item="item" index="index" open="begin" close=";end;" separator=";">
UPDATE EPJT_SBSJ_DBXX
<set>
RES_UP_STATUS=3,
res_local_err_desc=#{item.resLocalErrDesc},
res_local_err_code=#{item.resLocalErrCode},
RES_UP_TIME = #{item.resUpTime}
</set>
where RES_UP_STATUS=1 AND SBSJID = #{item.sbsjid}
</foreach>
</update>
dao接口:
public int doupdateBatchResUpStatusById(List<T> listObject)throws Exception;
二、db2as400+mybatis执行批量更新:
mapper.xml:
<update id="doupdateBatchResUpStatusById" parameterType="java.util.List">
<foreach collection="list" item="item" index="index" open="BEGIN" close=";END" separator=";" >
UPDATE EPJT_SBSJ_DBXX
<set>
RES_UP_STATUS=3,
<if test="item.resLocalErrDesc != null ">
res_local_err_desc='${item.resLocalErrDesc}',
</if>
<if test="item.resLocalErrCode != null ">
res_local_err_code='${item.resLocalErrCode}',
</if>
RES_UP_TIME = current timestamp
</set>
where RES_UP_STATUS=1 AND SBSJID = ${item.sbsjid}
</foreach>
</update>
dao接口:
public int doupdateBatchResUpStatusById(List<T> listObject)throws Exception;
三、db2aix+mybatis执行批量更新:
mapper.xml:
<update id="doupdateBatchResUpStatusById" parameterType="java.util.List">
<foreach collection="list" item="item" index="index" open="BEGIN" close=";END" separator=";" >
UPDATE EPJT_SBSJ_DBXX
<set>
RES_UP_STATUS=3,
res_local_err_desc=#{item.resLocalErrDesc,jdbcType=VARCHAR},
res_local_err_code=#{item.resLocalErrCode,jdbcType=VARCHAR},
RES_UP_TIME = #{item.resUpTime,jdbcType=DATE}
</set>
where RES_UP_STATUS=1 AND SBSJID = #{item.sbsjid,jdbcType=INTEGER}
</foreach>
</update>
dao接口:
public int doupdateBatchResUpStatusById(List<T> listObject)throws Exception;
————————————————
版权声明:本文为CSDN博主「zhengzixiang666」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/zhengzixiang666/article/details/89472734
本文详细介绍使用MyBatis在不同数据库(Oracle、DB2AS400、DB2AIX)环境下执行批量更新操作的方法,包括mapper.xml配置与DAO接口实现,适合于需要进行高效数据更新的开发人员。

1959

被折叠的 条评论
为什么被折叠?



