【批量修改】
xxxMapper.java:
/**
* 批量修改指定记录的属性字段
*
* @param updateVo 待修改属性字段
* @param idList id集合
* @return
*/
Integer batchUpdateFields(@Param("vo")UpdateVo updateVo, @Param("list")List<String> idList);
xxxMapper.xml:
<!-- 批量修改指定记录的属性字段 -->
<update id="batchUpdateFields">
update t_xxx
<trim prefix="set" suffixOverrides=",">
<if test="vo.status!= null">
<trim prefix="status= case" suffix="end,">
<foreach collection="list" item="item">
when id = #{item} then #{vo.status}
</foreach>
</trim>
</if>
<if test="vo.updateTime != null">
<trim prefix="update_time = case" suffix="end,">
<foreach collection="list" item="item">
when id = #{item} then #{vo.updateTime}
</foreach>
</trim>
</if>
</trim>
where id in
<foreach collection="list" index="index" item="item" separator="," open="(" close=")">
#{item}
</foreach>
</update>
上述批量修改的sql实际执行:
update t_xxx
set
status = case
when id = ? then ?
when id = ? then ?
when id = ? then ?
when id = ? then ?
end,
update_time = case
when id = ? then ?
when id = ? then ?
when id = ? then ?
when id = ? then ?
end
where id in ( ? , ? , ? , ? )