IFNULL

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

转载于:https://www.jianshu.com/p/ad1e2c317f70

猜你喜欢

转载自blog.csdn.net/weixin_34038293/article/details/91052253