解决mybatis查询resultType是HashMap,字段值为null,结果集问题

<select id="select" parameterType="xx" resultType="java.util.HashMap">
    select a,b,c,d,e from t_order o 
</select>


假设SQL查询有3条记录,
第一条所有字段都有值,
第二条字段b为null,e为空字符串
第三条c、d 字段结果为null
那么结果为
[{a=xx, b=xx, c=xx, d=xx, e=xx}, 
 {a=xx, c=xx, d=xx, e=},
 {a=xx, b=xx, e=xx}]


想要结果集显示为
[{a=xx, b=xx, c=xx, d=xx, e=xx}, 
 {a=xx, b=null, c=xx, d=xx, e=},
 {a=xx, b=xx, c=null, d=null, e=xx}]


在mybatis-config.xml配置文件中加下面这句代码即可解决
<!-- 在null时也调用 setter,适应于返回Map,3.2版本以上可用 --> 
<setting name="callSettersOnNulls" value="true"/>

猜你喜欢

转载自wellba.iteye.com/blog/2213114