mybatis批量更新update

it2022-12-27  83

//第一种方法 <udpate id = "方法名" parameter = "java.util.List"> update `表名` <trim prefix = "set" suffixOverrides = ","> <trim prefix = "字段1 = case" suffix= "end,"> <foreach collection ="list" item = "item" index ="index"> when ID = #{item.ID} then #{item.参数1} </foreach> </trim> <trim prefix = "字段2 = case" suffix = "end,"> <foreach collection = "list" item = "item" index = "index"> when ID = #{item.ID} then #{item.参数2} </foreach> </trim> </trim> where <foreach collection = "list" separator = "or" item = "item" index = "index"> ID = #{item.ID} </foreach> </update> //第二种方法 <update id ="方法名" parameterType = "java.util.List"> <foreach collection = "list" item = "item" index = "index" open ="begin" close=";end;" separator =";" > UPDATE '表' <set> <if test = "item.参数1!=null and item.参数1 !=""toString()"> '对应表字段1' = #{item.参数1} </if> <if test = "item.参数2!=null and item.参数2 !="".toString()"> '对应表字段2' = #{item.参数2} </if> </set> where id = #{item.id} </foreach> </update>
最新回复(0)