新地址: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;
}
}
}
}
本文探讨了MyBaits框架中INT类型字段的特殊处理方式,指出不能使用sub_name!=null and ''!=field_name的条件判断,而应简化为sub_name!=null。此外,提供了一个实用的代码片段,用于从JSON对象中移除所有空值字段,以优化数据处理流程。
3395

被折叠的 条评论
为什么被折叠?



