處理查詢數據All elements are null


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

查詢結果

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 &lt;> #{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));


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM