1,根据指定id,更新特定字段的值(批量更新)
<update id="updatePageAliasList" parameterType="java.util.List">
UPDATE t_web_page_alias set url_name = CASE id
<foreach collection="list" index="index" item="item">
WHEN #{item.id} THEN #{item.urlName}
</foreach>
END,
url_desc = CASE id
<foreach collection="list" index="index" item="item">
WHEN #{item.id} THEN #{item.urlDesc}
</foreach>
END
WHERE id IN
<foreach collection="list" index="index" item="item" open="(" close=")" separator=",">
#{item.id}
</foreach>
</update>
SQL: select * from table where id IN (3,6,9,1,2,5,8,7);
这样的情况取出来后,其实,id还是按1,2,3,4,5,6,7,8,9,排序的,但如果我们真要按IN里面的顺序排序怎么办?SQL能不能完成?是否需要取回来后再foreach一下?其实mysql就有这个方法
select * from test where id in(3,1,5) order by find_in_set(id,'3,1,5');