Mybatis中执行查询语句,返回空null字段不显的解决方法

       在查询数据库某个表进行分页输出时候,开始我以为是PageHelper分页组件的问题,后来发现Mybatis输出直接就没字段了。对于后台数据处理输出来说,这是一个致命的问题,于是通过修改Mybatis的配置来解决这个问题。

mybatis.configuration.call-setters-on-nulls=true

     在springboot中,则有时不起作用。经过研究,其实在SqlSessionFactory增加callSettersOnNulls的配置就可以了,这里记录一下:

SqlSessionFactoryBean bean = new SqlSessionFactoryBean();
org.apache.ibatis.session.Configuration configuration = new org.apache.ibatis.session.Configuration();
configuration.setCallSettersOnNulls(true);
bean.setConfiguration(configuration);

如遇到以上问题,大家可以用此方法解决!

猜你喜欢

转载自blog.csdn.net/Angel_asp/article/details/130250888
今日推荐