`
yjhexy
  • 浏览: 327258 次
  • 性别: Icon_minigender_1
  • 来自: 火星
社区版块
存档分类
最新评论

ibatis nullvalue 探究

阅读更多

在我们配置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  了。

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics