数据库-oracle-mybatis

mybatis中Oracle参数为NULL错误解决:
原因是当插入数据为null类型的时候,mybatis会自动转换为JdbcType.OTHER类型,因此需要修改一下参数的转换类型

@Bean
public SqlSessionFactory sqlSessionFactory() throws Exception {
    SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean();
    sqlSessionFactoryBean.setVfs(SpringBootVFS.class);
    DataSource dataSource = dataSource();
    org.apache.ibatis.session.Configuration configuration = new org.apache.ibatis.session.Configuration();
    configuration.setUseColumnLabel(true);
    configuration.setMapUnderscoreToCamelCase(true);
    configuration.setJdbcTypeForNull(JdbcType.NULL);
    sqlSessionFactoryBean.setConfiguration(configuration);
    sqlSessionFactoryBean.setDataSource(dataSource);
    sqlSessionFactoryBean.setTypeAliasesPackage(env.getProperty("mybatis.type-aliases-package"));

    // 添加Mybatis 拦截器插件
    //        sqlSessionFactoryBean.setPlugins(new Interceptor[]{new SqlLogInterceptor()});

    return sqlSessionFactoryBean.getObject();
}

猜你喜欢

转载自blog.csdn.net/yulong1026/article/details/81017362
今日推荐