<!-- void updateSaleCount(@Param("items") List<UGoodVo> items); -->
<update id="updateSaleCount" >
<foreach collection="items" item="item" separator=";">
update goods
set saleCount = saleCount + #{item.quantity}
where goodsId = #{item.goodsId}
</foreach>
</update>
上述代码是批量更新的操作,当集合长度大于1时,执行总是不成功。
原因是mybatis默认不支持批量操作,需要在数据库连接配置文件的url中追加允许批量操作的属性。
属性如下
&allowMultiQueries=true