Skip to content

Commit 0f1b105

Browse files
committed
新增支持子查询对象内省略关键词 from,自动取最上方的表对象 key 作为 from
1 parent db8bc96 commit 0f1b105

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

APIJSONORM/src/main/java/apijson/orm/AbstractObjectParser.java

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ public AbstractObjectParser parse(String name, boolean isReuse) throws Exception
258258
if (obj instanceof JSONObject) {
259259
((JSONObject) obj).put(apijson.JSONObject.KEY_METHOD, GET);
260260
}
261-
261+
262262
try {
263263
boolean startsWithAt = key.startsWith("@");
264264
//if (startsWithAt || (key.endsWith("()") == false)) {
@@ -372,7 +372,21 @@ public boolean onParse(@NotNull String key, @NotNull Object value) throws Except
372372
}
373373

374374
String from = subquery.getString(JSONRequest.KEY_SUBQUERY_FROM);
375-
JSONObject arrObj = from == null ? null : obj.getJSONObject(from);
375+
boolean isEmpty = StringUtil.isEmpty(from);
376+
JSONObject arrObj = isEmpty ? null : obj.getJSONObject(from);
377+
if (isEmpty) {
378+
Set<Entry<String, Object>> set = obj.entrySet();
379+
for (Entry<String, Object> e : set) {
380+
String k = e == null ? null : e.getKey();
381+
Object v = k == null ? null : e.getValue();
382+
if (v instanceof JSONObject && JSONRequest.isTableKey(k)) {
383+
from = k;
384+
arrObj = (JSONObject) v;
385+
break;
386+
}
387+
}
388+
}
389+
376390
if (arrObj == null) {
377391
throw new IllegalArgumentException("子查询 " + path + "/"
378392
+ key + ":{ from:value } 中 value 对应的主表对象 " + from + ":{} 不存在!");

0 commit comments

Comments
 (0)