出现的原因是数据库查询出空数据并填充了实体
查询结果
SpringBoot是用map接收
<select id="check" resultType="java.util.Map">
SELECT
p.address_name AS `name`
FROM
pm_rules_items r
LEFT JOIN pm_mountain_address p ON p.mountain_id = r.mountains_id
<where>
<if test="id!=null">
r.rules_id <> #{id}
</if>
<if test="items!=null">
AND r.mountains_id IN
<foreach collection="items" item="item" open="(" close=")" separator=",">
#{item.mountainsId}
</foreach>
</if>
</where>
</select>
dao层接口
List<Map<String, String>> check(@Param("id") Integer id, @Param("items") List<RulesItemParam> items);
最后确实组装进集合,集合的长度为1但是内容为空,提示All elements are null
解决方案,处理前去除null元素,不然判断该集合是不为空
resultMap.removeAll(Collections.singleton(null));
处理查询数据All elements are null