mybatis返回数据类型为map,值为null的key没返回

时间:2022-06-14 19:35:57

创建mybatis-config.xml

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
    <settings>  
    	<!-- 当返回数据类型为map,设置callSettersOnNulls会把值为null的key也返回 -->
        <setting name="callSettersOnNulls" value="true"/>  
    </settings> 
</configuration>

 在配置数据源的配置文件中,配置Mybatis的SqlSessionFactoryBean

 

<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
    <property name="dataSource" ref="dataSource" />
    <property name="configLocation" value="classpath:/META-INF/spring/mybatis-config.xml" />
    <property name="mapperLocations">
	<array>
	  <value>classpath*:/yunnex/saofu/shop/beibao/mapper/*.xml</value>
	</array>
  </property>
</bean>

 

 重新启动即可