主要我们就要把更新的sql语句拆分的思路来想就对了。然后就是更新的字段当作多个标签来操作。
1、server
List<tableStateVo> dataState
Map<String,Object> map = new HashMap<String,Object>();
map.put("list", dataState);
return tableMapper.updateBatch(map);
2、接口Mapper
int updateBatch(Map<String, Object> map);
3、XML mybatis
<update id="updateBatch" parameterType="java.util.List">
update table t
<trim prefix="set" suffixOverrides=",">
<trim prefix="t.field1=case" suffix="end,">
<foreach collection="list" item="item" index="index"> when
id=#{item.id} then #{item.field1} </foreach>
</trim>
<trim prefix="t.field2=case" suffix="end,">
<foreach collection="list" item="item" index="index"> when
id=#{item.id} then #{item.field2} </foreach>
</trim>
</trim>
where id in
<foreach collection="list" index="index" item="item" separator=","
open="(" close=")"> #{item.id,jdbcType=BIGINT} </foreach>
</update>