int selectCartProductCount(Integer userId)
<select id="selectCartProductCount">
select sum(count) as count from mmall_cart where user_Id = #{userId}
</select>
当 userId 不存在时,select 语句返回空,空值无法赋给基本类型 int,应将数据库语句改为
<select id="selectCartProductCount">
select IFNULL(sum(quantity), 0) as count from mmall_cart where user_Id = #{userId}
</select>
如果 sum(quantity)值为空则设为默认值 0
网友评论