目的是拼出 update table set column = value where id in ('a','b','c',...) 这样的 sql 语句,方法如下:
DAO:
int updateBatch(String[] ids, String state);
Mapper:
<update id="updateBatch" parameterType="String">
update t_people set state = #{1}
where id in
<foreach item="item" collection="param1" open="(" separator="," close=")">
#{item}
</foreach>
</update>
其中,#{n} 是从0 开始计数,此处 #{1} 代表的是DAO 中的第二个参数 state ,而 paramn 中的 n 是从 1 开始计数, 此处 param1 代表的是 DAO 中的第一个参数 ids .
End .