因为mysql比较灵活,现在springboot项目中集成数据库几乎都是采用mysql,由于公司项目需要,任然采用oralce数据库,
在开发时遇到下面问题。
Cause: org.apache.ibatis.type.TypeException: Error setting null for parameter #17 with JdbcType OTHER,
Try setting a different JdbcType for this parameter or a different jdbcTypeForNull configuration property
经过debug,发现在插入数据为空时,mybatis对于oralce数据库中,在Configuration类中初始化jdbcTypeForNull默认值是
Other,这样就会报错
public void setJdbcTypeForNull(JdbcType jdbcTypeForNull) {
this.jdbcTypeForNull = jdbcTypeForNull;
}
所以解决办法就是修改mybatis对于插入空数据的jdbcTypeForNull默认值
方法一
在字段上添加注解
el = " 字段名, jdbcType=字段类型 "
比如本例
@TableField(strategy= FieldStrategy.IGNORED,el = "remarks, jdbcType=VARCHAR")
protected String remarks;
方法二
修改配置文件 application.yml
mybatis-plus:
configuration:
jdbc-type-for-null: 'null' #注意:单引号
两个方法各有利弊,修改配置文件时针对所有的空字段都进行空处理,如果有些字段空值默认值需要传入0或者其他时,
可以采用字段注解方式