码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2020-03-01 18:19:00      阅读:70      评论:0      收藏:0      [点我收藏+]

标签:post   就会   避免   with   class   div   temp   原因   return   

错误信息:

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) from post where post.author = ?

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

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

标签:post   就会   避免   with   class   div   temp   原因   return   

原文地址:https://www.cnblogs.com/youcong/p/12391106.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!