mybatis返回map类型数据空值字段不显示

1.springMVC+mybatis查询数据,返回resultType=”map”时,如果数据为空的字段,则该字段省略不显示,可以通过添加配置文件,规定查询数据为空是则返回null。

mybatis-configuration.xml



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

spring-mybatis.xml

 
  <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
    <property name="dataSource" ref="dataSource"/>
    <property name="configLocation" value="classpath:mybatis-configuration.xml"/>
    
    <property name="mapperLocations" value="classpath:mapping/*.xml">property>
  bean>

2.查询sql添加每个字段的判断空

IFNULL(age,'') as age

但是该方法需要判断每一个字段,使用不方便。

你可能感兴趣的:(mybatis)