List<TbDepartment>将整个集合的对象根据对应的ID进行更新到tb_department表。
mapper.xml
mapper.xml
<!-- 批量更新After表数据 -->
<update id="updateBatch" parameterType="java.util.List">
update TB_DEPARTMENT
<trim prefix="set" suffixOverrides=",">
<trim prefix="s1 = case" suffix="end,">
<foreach collection="list" item="i" index="index">
when id=#{i.id,jdbcType=INTEGER} then #{i.s1,jdbcType=VARCHAR}
</foreach>
</trim>
<trim prefix="s2 = case" suffix="end,">
<foreach collection="list" item="i" index="index">
when id=#{i.id,jdbcType=INTEGER} then #{i.s2,jdbcType=VARCHAR}
</foreach>
</trim>
<trim prefix="s3 = case" suffix="end,">
<foreach collection="list" item="i" index="index">
when id=#{i.id,jdbcType=INTEGER} then #{i.s3,jdbcType=VARCHAR}
</foreach>
</trim>
</trim>
where
<foreach collection="list" separator="or" item="i" index="index" >
id=#{i.id,jdbcType=INTEGER}
</foreach>
</update>
java调用代码:
List<TbDepartment> list = new ArrayList<TbDepartment>();
sqlSessionTemplate.update("updateBatch", list);

本文介绍了一种使用MyBatis进行批量更新数据的方法。通过Mapper文件中的动态SQL实现对多个对象的属性进行批量更新,并提供了具体的XML配置示例及Java调用代码。
2372

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



