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

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了attempted to return null from a method with a primitive return type (double)相关的知识,希望对你有一定的参考价值。

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

场景:

服务启动正常,接口调用时出现异常。

业务描述:通过用户标识获取用户目前为止的所有投资收益。但测试使用的用户是新注册的用户,无投资金额。


解决:

  1. DEBUG模式跟踪,发现底层mapper.xml 中的 SQL

  2. select sum(invest) from db
  3. 此时 invest 为空 , sum (null) , 赋值给 double ,所以系统提示异常,尝试把一个 null值复制给 double 类型数据

  4. select IFNULL(sum(invest),0) FROM DB
  5. 返回值时进行判断,若为空,则返回0

  6. mapper的返回值,尽量使用包装类

本文出自 “工作常用工具类” 博客,请务必保留此出处http://mingyundezuoan.blog.51cto.com/4012317/1934283

以上是关于attempted to return null from a method with a primitive return type (double)的主要内容,如果未能解决你的问题,请参考以下文章

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

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

attempt to create delete event with null entity

java.lang.IllegalArgumentException: attempt to create saveOrUpdate event with null entity

Attempted to call method length on null context object和“arrays.length(tag.blogs)“ (template: “tags“)

Attempt to invoke interface method 'boolean java.util.List.add(java.lang.Object)' on a null