一、报错及原因
1.spring
2.spring MVC
3.mybatis
3.1 Cause: org.apache.ibatis.type.TypeException: Error setting null for parameter #7 with JdbcType OTHER
with JdbcType OTHER的意思即使用了其他jdbc类型,在mybatis中,插入空值时需要自行指定jdbcType,否则会报上述的错误,个人理解是null在mybatis中有默认的jdbcType值,如果不指定的话,mybatis会根据传入值的类型进行指定。而在pl/sql或命令行中直接使用null插入是没有问题的。指定方式如下所示的最后两个:
<insert id="addUser" parameterType="com.pcw.bean.User">
<selectKey keyColumn="userid" keyProperty="userid" resultType="long" order="BEFORE">
select ques_seq.nextval from dual
</selectKey>
insert into ques_user(userid,gender,username,password,birth,phonenum,email) values(#{userid},#{gender},#{username},#{password},#{birth},#{phonenum,jdbcType=CHAR},#{email,jdbcType=VARCHAR})
</insert>