mybaits int 类型的字段不能

只能

如果 <if ‘’ != field_name”> ,值为 0 时 if 条件为 false

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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
/**
* 移除空值字段
*
* @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;
}
}
}
}