直接上代码
void batchUpdateSpecificationId(@Param("infos") List<GoodsInfo> infos);
<update id="batchUpdateSpecificationId">update goods_infoset specification_id =<foreach collection="infos" item="info" open="(case " close=" else null end)">when id = #{info.id} then #{info.specificationId}</foreach>,specification_name =<foreach collection="infos" item="info" open="(case " close=" else null end)">when id = #{info.id} then #{info.specificationName}</foreach>,min_real_price =<foreach collection="infos" item="info" open="(case " close=" else null end)">when id = #{info.id} then #{info.minRealPrice}</foreach>,min_line_price =<foreach collection="infos" item="info" open="(case " close=" else null end)">when id = #{info.id} then #{info.minLinePrice}</foreach>where id in<foreach collection="infos" item="info" open="(" close=")" separator=",">${info.id}</foreach></update>
运行的sql
UPDATE goods_info
SET specification_id = ( CASE WHEN id = 373 THEN '702' WHEN id = 374 THEN '704' ELSE NULL END ),
specification_name = ( CASE WHEN id = 373 THEN '十全冻干桶 | 400g' WHEN id = 374 THEN '经典混合 | 60支' ELSE NULL END ),
min_real_price = ( CASE WHEN id = 373 THEN 0.01 WHEN id = 374 THEN 0.01 ELSE NULL END ),
min_line_price = ( CASE WHEN id = 373 THEN 130.0 WHEN id = 374 THEN 88.0 ELSE NULL END )
WHEREid IN ( 373, 374 )
这辈子坚持与不坚持都不可怕,怕的是独自走在坚持的道路上。。