一、报错及原因
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>
本文探讨了在使用MyBatis框架时遇到的空值插入问题及其解决办法。具体分析了当尝试将null值插入数据库时出现的TypeException异常,并提供了一种通过显式指定JDBC类型来避免该问题的方法。
5773

被折叠的 条评论
为什么被折叠?



