版权声明:原创内容是本人学习总结,仅限学习使用,禁止用于其他用途。如有错误和不足,欢迎评论指正补充。 https://blog.csdn.net/qian_qian_123/article/details/84581244
在mybatis中,SQL语句在插入时默认不允许插入null值,如果在页面中传过来null值,在插入操作时会报错
org.apache.ibatis.exceptions.PersistenceException:
### Error updating database. Cause: org.apache.ibatis.type.TypeException: Error setting null for parameter #4 with JdbcType OTHER . Try setting a different JdbcType for this parameter or a different jdbcTypeForNull configuration property. Cause: java.sql.SQLException: 无效的列类型: 1111
### The error may involve dao.CarDao.addCar-Inline
### The error occurred while setting parameters
如果要想可以插入null值,只需要在主配置文件中如下配置:
<settings>
<!-- 设置对mybatis全局的配置 -->
<!-- 允许插入null -->
<setting name="jdbcTypeForNull" value="NULL"/>
</settings>入时默认不允许插入null值