异常信息:
org.apache.ibatis.binding.BindingException: Mapper method ‘CartMapper.testSum attempted to return null from a method with a primitive return type (int).
// CartMapper
int testSum(Integer userId);
<select id="testSum" resultType="int">
SELECT sum(quantity)
FROM mall_cart
WHERE user_id = #{userId}
</select>
原因:
试图从具有原始返回类型(int)的方法返回null。
数据库函数sum()在找不到记录时, 会返回null
解决方案
<select id="testSum" resultType="int">
SELECT sum(quantity)
FROM mall_cart
WHERE user_id = #{userId}
</select>