1. Origin of the problem
When viewing the log, I found that a line of error message was printed in the log:
The data of assembled pets that have been released is abnormal — & gt; Mapper method ‘applets. user. mapper. xxxMapper. xxxmyRank attempted to return null from a method with a primitive return type (int).
The meaning is well understood. The query method of xxxmyrank in a mapper file returns null, but it needs to return an int type number, so an error is reported.
2. Problem analysis
Fdafdsaf query is a simple query used to query a ranking. If you query the ranking yourself, you can use int type to receive it. At the beginning of the test, there was no problem, but after the project was really launched
Report this problem before you know that this problem exists in the previously written code. The reason for this problem is that the database does not query the corresponding data, so it returns a null value. When you write your own code, you use the int type receive. As shown in the figure below:
3. Solution
After finding the cause of the problem, it is easy to solve it. Change the received int type to the wrapper type integer type class for reception, so as to solve this problem. Because the integer type can be null, regardless of the specific value returned
Or a null value, can receive. Then, you can process the null value in the code, and the problem is solved.
Expansion: this method is mainly used in query. When writing custom numeric fields in Java code, it is best to use the wrapper type to receive them,
Byte,Boolean,Short ,Character,Integer,Long,Float,Double.
The principle is the same. If you query the entity class or use the entity class to accept the value passed by the front end, there may be no value null. At this time, using the wrapper type can solve this problem.
Similar Posts:
- [Solved] IDEA Unboxing of ‘stringRedisTemplate.hasKey(xx)’ may produce ‘NullPointerException’
- [Solved] Mybatis Mapping Error: nested exception is org.apache.ibatis.reflection.ReflectionException: There is no getter for property named ‘id’ in ‘class java.lang.String
- [Solved] Spark Streaming:updateStateByKey is not applicable for the arguments…
- [Solved] java.lang.ClassCastException: Ljava.lang.Object; cannot be cast to com.entity.Advertisem
- Python Error:Exception Value:can only concatenate str (not “bytes”) to str
- [Solved] mapper.xml Error: java.lang.AbstractMethodError: Method oracle/jdbc/driver/OracleResultSetImpl.getNString(Ljava/lang/String;)Ljava/lang/String; is abstract,
- [Solved] org.springframework.dao.EmptyResultDataAccessException: Incorrect result size: expected1, actual0
- After introducing mybatisplus, the user-defined method is used to solve the invalid bound statement (not found) error
- [Solved] Mybatis Error: org.apache.ibatis.cache.CacheException: Error serializing object. Cause: java.io.NotSerializableExc
- System.Data.SqlTypes.SqlNullValueException: ‘Data is Null. This method or property cannot be called on Null values.’