This error occurs when a MyBatis mapper method returns null but the return type is a primitive type such as long, int, boolean, etc. Primitive types cannot be null in Java, so MyBatis throws this exception to indicate that the returned value is invalid.

To fix this error, you need to modify the mapper method to return an appropriate value when null is encountered. One way to do this is to change the return type to a wrapper class such as Long, Integer, Boolean, etc. These wrapper classes can handle null values and can be used as a substitute for their corresponding primitive types.

For example, you can modify the mapper method to return a Long instead of a long, like this:

public Long getDayMoneyTotal();

Then, in the implementation of the method, you can return null if the result of the query is null:

Long result = // execute query to get result; if (result == null) { return null; } return result;

By using a wrapper class, you can handle null values without causing a BindingException

orgapacheibatisbindingBindingException Mapper method comaryapaydaoOrderInfoDaogetDayMoneyTotal attempted to return null from a method with a primitive return type long

原文地址: https://www.cveoy.top/t/topic/fhtE 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录