MyBatis resultType用Map 返回值中有NULL则缺少字段 返回值全NULL则map为null
这个问题我大概花了2个小时才找到结果
总共需要2个设置
这里是对应springboot中的配置写法
@select("select sum(a) a,sum(b) b from XXX where XXX; ")
Map<String, Object> sumXXX(XXX);
Map map = sumXXX(args);
| a | b |
|---|---|
| NULL | NULL |
| 期望结果 | |
| map : | |
| 实际结果 | |
| map : null |
mybatis.configuration.call-setters-on-nulls=true
这个设置很容易搜索到
并没有变换
测试发现
如果结果是
| a | b |
|---|---|
| 1 | NULL |
| 默认设置时 | |
| map : | |
设置mybatis.configuration.call-setters-on-nulls=true后 |
|
| map : |
第二个设置我并没有google到 可能形容的不准确
我是花了将近2个小时一步步debug找到的
mybatis.configuration.return-instance-for-empty-row=true
这个一起设置才能返回期望结果
能用注解的,尽量不用xml,看着xml就烦!!!
浙公网安备 33010602011771号