The service starts normally, but an exception occurs when the interface in MyBatis Interface is called.
Business description:
Obtain all the user's investment income so far through the user ID. However, the users used in the test are newly registered users, and there is no investment amount.
Problem analysis:
DEBUG mode tracking, find the SQL in the underlying mapper.xml
select sum(invest) from db
At this time, invest is empty, sum (null) is assigned to double, so the system prompts an exception, try to copy a null value to double type data
Problem conclusion:
1. Add function to evaluate null
select IFNULL(sum(invest),0) FROM DB
Judgment is made when returning the value. If it is empty, the
return value of mapper will be 0, and the wrapper class should be used as much as possible.
2. Modify the resultType = Double of the select interface in mybatis to double
. If the result is empty, it will return 0 by default.