<update id="updateBatch" parameterType="java.util.List">
<foreach collection="list" item="item" index="index" open="" close="" separator=";">
update deviceparameterdetail
<set>
<if test="item.DeviceParameteValue != null">
DeviceParameteValue = #{item.DeviceParameteValue,jdbcType=VARCHAR},
</if>
<if test="item.UploadFlag != null">
UploadFlag = #{item.UploadFlag,jdbcType=BIT},
</if>
<if test="item.UpdateTime != null">
UpdateTime = #{item.UpdateTime,jdbcType=TIMESTAMP},
</if>
<if test="item.ProcotolID != null">
ProcotolID = #{item.ProcotolID,jdbcType=INTEGER},
</if>
</set>
where
DeviceID = #{item.DeviceID,jdbcType=VARCHAR} and
DeviceParameterCode = #{item.DeviceParameterCode,jdbcType=VARCHAR}
</foreach>
</update>
需要注意的是:必须在配置连接数据库url后面带一个参数 &allowMultiQueries=true,表示允许批量操作,例
url: jdbc:mysql://127.0.0.1:3306/cw_vehicle?useUnicode=true&characterEncoding=UTF-8&connectionCollation=utf8mb4_general_ci&serverTimezone=GMT%2B8&allowMultiQueries=true
本文介绍如何使用MyBatis进行批量更新操作,通过一个具体的XML映射文件示例,展示如何设置foreach循环和if条件判断,实现对List集合中多个对象属性的批量更新。同时,强调了在数据库URL中添加特定参数以启用批量操作的重要性。

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



