mybaits int 類型的字段不能 Java 移除 JSONObject 空值字段

新地址:https://blog.iaiot.com/mybaits-int.html

mybaits int 類型的字段不能 <if test="sub_name != null and '' != field_name">

只能 <if test="sub_name != null">

如果 <if '' != field_name"> ,值爲 0 時 if 條件爲 false

 

可以直接在代碼中移除空值字段

    /**
     * 移除空值字段
     *
     * @param json json
     */
    public static void rmEmptyField(JSONObject json) {
        if (json != null) {
            // 遍歷 json 副本,修改原 json,防止 ConcurrentModificationException
            JSONObject jsonCopy = (JSONObject) json.clone();
            Set<String> jsonKeys = jsonCopy.keySet();
            for (String jsonKey : jsonKeys) {
                // 移除空值字段
                if (json.getString(jsonKey) == null || "".equals(json.getString(jsonKey).trim())) {
                    json.remove(jsonKey);
                    continue;
                }
            }
        }
    }

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章