使用ibatis nullvalue

来源:互联网 发布:linux expect telnet 编辑:程序博客网 时间:2024/04/26 01:28

使用场景:

java对象类是用基本数据类型,但是数据库中的字段信息为空时,可以防止转换时抛出java.lang.IllegalArgumentException异常


<resultMap id="userResult" class="user"> 


    <result property="birthDay"  column="BirthDay" /> 

    <result property="education"  column="Education" nullValue="0" /> 

    <result property="post"  column="Post" nullValue="0" /> 

</resultMap> 


如:以上配置,其中birthDay为Date类型,education、post为int类型,如果没有设置nullValue="0",那么直接抛java.lang.IllegalArgumentException。 

因此,在使用的时候, 如果JAVA类里面是原生类型的int,float,double等的话,那么就需要配置 nullValue 了。

0 0
原创粉丝点击