出現的原因是數據庫查詢出空數據並填充了實體
查詢結果

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));