您的位置:首页 > 移动开发

[mybatis-异常]:BindingException: Mapper method 'CartMapper.testSum attempted to return null from a met

2018-04-25 12:24 1306 查看

异常信息:

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>
阅读更多
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐