加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

attempted to return null from a method with a primitive retu

发布时间:2020-12-14 18:05:42 所属栏目:大数据 来源:网络整理
导读:错误信息: attempted to return null from a method with a primitive return type ( int ). 错误原因: 实际查询sql并没有这个值,出现空值,就会报这个异常。 错误sql(发生问题): select sum(id) from post where post.author = ? 正确sql(解决问题): selec

错误信息:

attempted to return null from a method with a primitive return type (int).

错误原因:
实际查询sql并没有这个值,出现空值,就会报这个异常。

错误sql(发生问题):

select sum(id) from post where post.author = ?

正确sql(解决问题):

select IFNULL(sum(id),0) where post.author = ?

关键在于使用了IFNULL,有了这个判断可避免任何情况空值导致的错误。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读