1.第一步
int updateBatchById(@Param("list") List<JdpTbTrade> list);
2.第二步
<!--批量更新订单-->
<update id="updateBatchById">
update `jdp_tb_trade`
<trim prefix="set" suffixOverrides=",">
<trim prefix="status =case" suffix="end,">
<foreach collection="list" item="item" index="index">
when tid=#{item.tid} then #{item.status}
</foreach>
</trim>
<trim prefix="modified =case" suffix="end,">
<foreach collection="list" item="item" index="index">
when tid=#{item.tid} then #{item.modified}
</foreach>
</trim>
<trim prefix="jdp_response =case" suffix="end,">
<foreach collection="list" item="item" index="index">
when tid=#{item.tid} then #{item.jdpResponse}
</foreach>
</trim>
<trim prefix="jdp_modified =case" suffix="end,">
<foreach collection="list" item="item" index="index">
when tid=#{item.tid} then #{item.jdpModified}
</foreach>
</trim>
</trim>
where tid in
<foreach collection="list" index="index" item="item" separator="," open="(" close=")">
#{item.tid,jdbcType=BIGINT}
</foreach>
</update>
![点击并拖拽以移动 wAAACH5BAEKAAAALAAAAAABAAEAAAICRAEAOw==](https://i-blog.csdnimg.cn/blog_migrate/45f4c756fb4acd7573d3f507666ee0d9.png)
3.总结
上面那种方式采用的是拼接字符串的形式,比用foreach批量插入快的不是一点半点,foreach那种批量其实还是一条一条插入。