在我们配置resultMap中有的时候需要配置 nullValue
<resultMap id="baby-Result" class="baby">
<result property="id" column="id" jdbcType="Integer" javaType="integer" />
<result property="name" column="name" jdbcType="VARCHAR" javaType="string" />
<result property="birthday" column="birthday" jdbcType="DATE" javaType="date" />
<result property="hobby" column="hobby" jdbcType="VARCHAR" javaType="string" />
<result property="age" column="age" jdbcType="INTEGER" javaType="int" nullValue="0"
/>
<result property="address" select="getAddressById" column="id" />
</resultMap>
这是因为当JAVA类中的age为int型的话,如果数据库里查出来的值是空,那么ibatis将用java 反射机制将这个null 赋值给 age。
就会抛如下错误:
Caused by: java.lang.IllegalArgumentException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
所以在使用的时候一定要注意如果JAVA类里面是原生类型的int,float,double等的话,那么就需要配置 nullValue 了。