Today I did something that cheated myself and wasted a lot of time. . .
In the settings of mybatis, I saw a line of settings like this. Out of the curiosity of the programmer, I searched and found what this setting does.
<setting name="callSettersOnNulls" value="true"/>
After the answers from many great masters on the Internet, I finally had a very little understanding.
In general queries, if you use map to accept the query result, the fields with the query result null will be automatically ignored, which will cause the null pointer exception to be reported when taking the parameter.
If this property is set, mybatis will not ignore these fields. You can still get these keys, but the value is null, which is also convenient.
So here comes the pitfall. In this setting, there will be two more special situations.
1. If all fields in the entire query have no value, that is, when 0 records are found, what is the result of the accepted map?
The answer is that we will receive a map with all key values null instead of a map with null.
2. If you only query one field and receive it with map, what is the result of null at this time?
The answer is that we will receive a map with null, which is exactly the opposite of the above.
Summarize
The above is the configuration analysis of mybatis callSettersOnNulls introduced to you. I hope it will be helpful to you. If you have any questions, please leave me a message. The editor will reply to you in time!