由于本人表达能力不是很好,如果下面所说不能让你理解,请告之....!谢谢!   以下给的分是我能给的最高分。
问题:
ibatis 使用外部映射,指定了nullValue属性,
向表中插入数据时,如果有参数为null,还是要报错
比如 下面的password未赋值时,会出问题
<parameterMap id="parameterUser" class="User">
<parameter property="name" nullValue=""/>
<parameter property="password" nullValue=""/>
<parameter property="age" nullValue="0"/>
</parameterMap><insert id="insertUser" parameterMap="parameterUser">
insert into user(name,password,age)
values(?,?,?)
</insert>javaBean为public class User{private String name;
private String password;
private int age;public void setName(String name){this.name=name;)}
public String getName{return this.name;}
public void setPassword(String password){this.password=password;}
public String getPassword{return this.password;}
public void setAge(int age){this.age=age;}
public int getAge{return this.age;}}.....................
//下面的代码访问数据库
SqlMapClient smc=......//构建一个SqlMapClient对象
User user=new User();
user.setName("admin");//只给name赋值,其它两个字段为空
smc.insert("insertUser",user);    //---------------------谢谢您的观看!....................

解决方案 »

  1.   

    insert into user(name,password,age) values(#name#,#password#,#age#) 
      

  2.   

    you can try again with<insert id="insertUser" parameterMap="parameterUser"> 
      insert into user(name,password,age) 
      values(
        <isNotNull property="name">
    #name#
        </isNotNull>
        <isNotNull property="password">
    #name#
        </isNotNull>
        <isNotNull property="age">
    #name#
        </isNotNull>
      ) 
    </insert> 
      

  3.   

    多谢高手指点,我知道怎么回事了,
    我以前也指定的jdbcType的类型,但是用的小写形式,这里好像必须用大写形式才可以