网上搜了说添加配置:
#空字段不返回解决方案,在在 spring.properties 配置文件中配置中加上该属性
mybatis.configuration.call-setters-on-nulls=true
加完依旧不管用,发现有人说多数据源需要单独配置数据源参数,于是在数据源配置文件中增加了如下一行配置:
@Primary
@Bean(name="firstSqlSessionFactory")
public SqlSessionFactory firstSqlSessionFactory(@Qualifier("firstDataSource")DataSource dataSource) throws Exception{
SqlSessionFactoryBean sqlSessionFactoryBean= new SqlSessionFactoryBean();
sqlSessionFactoryBean.setDataSource(dataSource);
//开启驼峰命名
sqlSessionFactoryBean.getObject().getConfiguration().setMapUnderscoreToCamelCase(true);
// 设置空值返回null
sqlSessionFactoryBean.getObject().getConfiguration().setCallSettersOnNulls(true);
return sqlSessionFactoryBean.getObject();
}
重启项目,空值正常返回,问题解决!
更多推荐
Mybatis空值不返回问题
发布评论