mybatis使用map做实体映射问题:获取字段值为null时默认不映射解决

mybatis中使用map作为实体映射结果是最常见的方式,但是在默认情况下查询到的字段值为null(仅仅是null,而不是空)时,map则不会映射该字段和null值。通过修改mybatis-config.xml配置文件来解决null值字段不映射问题。

1、在mybatis-config.xml文件中配置setting属性


<settings>  
    <setting name="callSettersOnNulls" value="true"/>  
</settings> 

2、需要在spring和mybatis的配置文件(这里是spring-mybatis.xml)SqlSessionFactoryBean配置property

<bean id="saasSqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
        <property ... />
        <!-- 引入mybatis-config.xml,让spring加载 -->
	<property name="configLocation" value="classpath:mybatis-config.xml"></property>
</bean>

猜你喜欢

转载自blog.csdn.net/FromTheWind/article/details/84786071