UPDATE course SET name = CASE id WHEN 1 THEN 'name1' WHEN 2 THEN 'name2' WHEN 3 THEN 'name3' END, title = CASE id WHEN 1 THEN 'New Title 1' WHEN 2 THEN 'New Title 2' WHEN 3 THEN 'New Title 3' END WHERE id IN (1,2,3)
在Mybatis中的配置则如下:
<update id="updateBatch" parameterType="list"> update course <trim prefix="set" suffixOverrides=","> <trim prefix="peopleId =case" suffix="end,"> <foreach collection="list" item="i" index="index"> <if test="i.peopleId!=null"> when id=#{i.id} then #{i.peopleId} </if> </foreach> </trim> <trim prefix=" roadgridid =case" suffix="end,"> <foreach collection="list" item="i" index="index"> <if test="i.roadgridid!=null"> when id=#{i.id} then #{i.roadgridid} </if> </foreach> </trim> <trim prefix="type =case" suffix="end," > <foreach collection="list" item="i" index="index"> <if test="i.type!=null"> when id=#{i.id} then #{i.type} </if> </foreach> </trim> <trim prefix="unitsid =case" suffix="end," > <foreach collection="list" item="i" index="index"> <if test="i.unitsid!=null"> when id=#{i.id} then #{i.unitsid} </if> </foreach> </trim> </trim> where <foreach collection="list" separator="or" item="i" index="index" > id=#{i.id} </foreach> </update>
标签:批量,Title,WHEN,when,多值,Mybatis,New,id From: https://www.cnblogs.com/xiaofengfree/p/17191734.html