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

错误信息:

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,有了这个判断可避免任何情况空值导致的错误。

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

时间: 2024-08-28 22:34:38

attempted to return null from a method with a primitive return type (int).的相关文章

Mapper method 'com.autoyol.mapper.trans.AccountLogMapper.getTotalIncomByMemNoLastest attempted to return null from a method with a primitive return type (int).解决方法

1.打开日志输出,降低日志级别. <AppenderRef ref="console" level="trace"></AppenderRef> 否则看不到报错.. 2.调整mysql语句,不能使用order by limit之类的 <!-- SELECT IFNULL(amt,1) FROM account_log WHERE mem_no=#{value} AND income_type != 4 ORDER BY id DESC

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

场景: 服务启动正常,接口调用时出现异常. 业务描述:通过用户标识获取用户目前为止的所有投资收益.但测试使用的用户是新注册的用户,无投资金额. 解决: DEBUG模式跟踪,发现底层mapper.xml 中的 SQL select sum(invest) from db 此时 invest 为空 , sum (null) , 赋值给 double ,所以系统提示异常,尝试把一个 null值复制给 double 类型数据 select IFNULL(sum(invest),0) FROM DB 返回

mybatis使用xml实现发生的异常之一return null from a method with a primitive return type (int)

主要原因: 1.接口的返回值错误 2.接口的xml错误  ( 主要是标签写错了) 在这里我的接口: 发现这句并没有错误,那我再看接口的xml: 很明显的就发现了select这里错误,insert,update,delect这些返回值为int类型,是不用写返回值的: 这里是标签写错了: 修改后的代码: 把resultType去掉: 原文地址:https://www.cnblogs.com/bichen-01/p/11730252.html

Null return value from advice does not match primitive

Exception in thread "main" org.springframework.aop.AopInvocationException: Null return value from advice does not match primitive return type for: public int com.fanling.xmlaop.UserDaoImpl.addUser(com.fanling.xmlaop.User) at org.springframework.

在Java中,return null 是否安全, 为什么?

Java代码中return value 为null 是不是在任何情况下都可以,为什么不会throw NullPointerException? Java语言层面:null值自身是不会引起任何问题的.它安安静静的待在某个地方(局部变量.成员字段.静态字段)不会有任何问题:它从一个地方被搬运到另一个地方也不会有任何问题(变量赋值.返回值等).唯一会因为null值而引起NullPointerException的动作是"解引用"(dereference)--也就是通过这个引用要对其引用的对象做

java中,return和return null有什么区别吗?

java中,return和return null有什么区别吗? 最大的区别:return;方法的返回值必须是void!return null;方法的返回值必须不是 原始数据类型(封装类除过)和void! return 就是跳出方法...return null也是跳出方法并返回null.. 也就是说return null必须用在返回值不是void的方法里面..return可以用在任何方法里面 不要认为null就是没有值..null就是值..真正的没有值是..比如你String s;这个时候s是没有

你写的return null有必要吗?

上次一篇"你写的try-catch真的有必要吗"引起了很多朋友的讨论.本次我在code review又发现了一个问题,那就是有人有意无意的写出了return null这样的代码,例如: public User GetUser(string userName, string password) { if ( /*for some reason*/) return null; return new User(); } 这样的写法有木有问题? 在我看来没有充分的理由不应该返回null,因为方

getActiveWorkbenchWindow() return null 解决办法

getActiveWorkbenchWindow 有如下声明 /** * Returns the currently active window for this workbench (if any). Returns * <code>null</code> if there is no active workbench window. Returns * <code>null</code> if called from a non-UI thread. *

java2_null、&quot;&quot;、return;、return null;、return &quot;&quot;;的比较

1,null的含义 null没有分配空间. 2,""的含义 ""表示这是一个String 类型,只不过是String的空类型. 3,null和""的比较 因为""是对象,null不是对象,对象比较要调用equals方法,所以对比代码为: if(null==""){//不会成立 System.out.println("NUll==\"\""); }else{ Syste