如何在mybatis中的结果映射中返回具有空值的列 [英] How to return columns with null values in a result map in mybatis
问题描述
< select id =keyEquipmentShiftAutomatedModelDataparameterType =java.util.MapresultType =java.util.Map>
SELECT ID,SUM(VALUE1 + VALUE2)总计< br $>
FROM tableName
GROUP BY ID
< / select>
退货以下结果在sql
ID,总计
1(null)
但是当在地图中返回结果时,myBatis返回{ID = 1},其中缺少Total。如何将带有null的列放入结果集中以及类似这样的内容{ID = 1,Total = null}或类似的内容{ID = 1,Total =}
<select id="keyEquipmentShiftAutomatedModelData" parameterType="java.util.Map" resultType="java.util.Map">
SELECT ID, SUM(VALUE1 + VALUE2) Total
FROM tableName
GROUP BY ID
</select>
Returns below result in sql
ID, Total
1 (null)
But when returned in Map result in myBatis returns {ID=1} where as Total is missing. How to get the column with null into the result set as well something like this {ID=1,Total=null} or something like this {ID=1,Total=""}
推荐答案
添加
< settings>
< setting name =callSettersOnNullsvalue =true>
mybatis-config.xml修复了使用mybatis 3.2 +版本
Adding
<settings>
<setting name="callSettersOnNulls" value="true">
mybatis-config.xml fixes the issue if using mybatis 3.2 + version
这篇关于如何在mybatis中的结果映射中返回具有空值的列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!