mybatis 数据库 oracle insert 时有些备用字段为空,保存报错,无效的列类型:1111
解决办法:
1、修改配置文件 application.yml 增加配置 jdbc-type-for-null: 'null' ,单引号不要忘了
mybatis:
mapper-locations: classpath:mapping/*/*.xml
configuration:
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
call-setters-on-nulls: true
jdbc-type-for-null: 'null'
2、在SQL语句里相应的属性上带上JDBCType
3、增加配置类
查看mp-starter-源码, MybatisPlusAutoConfiguration, 可以发现,第119行有一个configurationCustomizers,可以修改configuration 自定义一个,配上就完工
@Bean
public ConfigurationCustomizer configurationCustomizer(){
return new MybatisPlusCustomizers();
}
class MybatisPlusCustomizers implements ConfigurationCustomizer {
@Override
public void customize(org.apache.ibatis.session.Configuration configuration) {
configuration.setJdbcTypeForNull(JdbcType.NULL);
}
4、
第一步:把 可更新为空的 javabean 属性前加上注解:@TableField(el = "username, jdbcType=VARCHAR")
@Email
@TableField(el = "email, jdbcType=VARCHAR")
private String email;
第二步: 使用updateAllColumnById方法,而不是updateById. 如:
this.baseMapper.updateAllColumnById(user);
报错原因:
postgreSQL,MySQL,SQLSERVER都支持JdbcType.NULL类型,Oracle是不支持,适配的时候也因为这个问题导致mybatis报错。