动态删除购物车中的商品
错误的写法:
<update id="deleteCartByMultiGoodsId" parameterType="java.util.HashMap">
delete from ecs_cart where user_id=#{userId}
and goods_id in
<foreach collection="list" item="goodsIdList" index="index" open="(" separator="," close=")">
#{goodsIdList}
</foreach>
</update>
正确的写法:
<update id="deleteCartByMultiGoodsId" parameterType="java.util.HashMap">
delete from ecs_cart where user_id=#{userId}
and goods_id in
<foreach collection="goodsIdList" item="goodsIdList" index="index" open="(" separator="," close=")">
#{goodsIdList}
</foreach>
</update>
错误的原因在于:
"你可以传递一个 List 实例或者数组作为参数对象传给 MyBatis。当你这么做的时 候,MyBatis 会自动将它包装在一个 Map 中,用名称在作为键。List 实例将会以“list” 作为键,而数组实例将会以“array”作为键。"