<updateid="batchUpdate"parameterType="com.xxx.UserDTO"> UPDATE t_user <trimprefix="set"suffixOverrides=","> <trimprefix="name =case"suffix="end,"> <foreachcollection="list"item="item"> <iftest="item.name !=null"> when id=#{item.id} then #{item.name} </if> </foreach> </trim> <trimprefix="parent_name =case"suffix="end,"> <foreachcollection="list"item="item"> <iftest="item.parentName !=null"> when id=#{item.id} then #{item.parentName} </if> </foreach> </trim> </trim> where id in <foreachcollection="list"item="item"separator=","open="("close=")"> #{item.id} </foreach> </update>
in() 有序查询
1 2 3 4 5 6 7 8 9 10
<selectid="findByIdsWithSorted"parameterType="java.lang.Long"resultType="com.xxx.UserDTO"> SELECT * from t_user WHERE id IN <foreachcollection="list"item="item"open="("close=")"separator=","> #{item} </foreach> <foreachcollection="list"item="item"open="order by field(id,"close=")"separator=","> #{item} </foreach> </select>