Skip to content

Commit 9747549

Browse files
committed
Server:允许非 GET 方法使用子查询,以便实现多对多关联操作;解决子查询额外加的 []/0 路径导致嵌套层级过深报错
1 parent 29b578f commit 9747549

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

APIJSON-Java-Server/APIJSONORM/src/main/java/zuo/biao/apijson/server/AbstractObjectParser.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ public boolean onParse(@NotNull String key, @NotNull Object value) throws Except
308308
}
309309

310310

311-
JSONArray arr = parser.onArrayParse(subquery, AbstractParser.getAbsPath(path, replaceKey), "[]", true);
311+
JSONArray arr = parser.onArrayParse(subquery, path, key, true);
312312

313313
JSONObject obj = arr == null || arr.isEmpty() ? null : arr.getJSONObject(0);
314314
if (obj == null) {

APIJSON-Java-Server/APIJSONORM/src/main/java/zuo/biao/apijson/server/AbstractParser.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -787,7 +787,7 @@ public JSONArray onArrayParse(JSONObject request, String parentPath, String name
787787
}
788788

789789
//不能允许GETS,否则会被通过"[]":{"@role":"ADMIN"},"Table":{},"tag":"Table"绕过权限并能批量查询
790-
if (RequestMethod.isGetMethod(requestMethod, false) == false) {
790+
if (isSubquery == false && RequestMethod.isGetMethod(requestMethod, false) == false) {
791791
throw new UnsupportedOperationException("key[]:{}只支持GET方法!不允许传 " + name + ":{} !");
792792
}
793793
if (request == null || request.isEmpty()) {//jsonKey-jsonValue条件
@@ -855,7 +855,7 @@ public JSONArray onArrayParse(JSONObject request, String parentPath, String name
855855

856856

857857
//key[]:{Table:{}}中key equals Table时 提取Table
858-
int index = name == null ? -1 : name.lastIndexOf("[]");
858+
int index = isSubquery || name == null ? -1 : name.lastIndexOf("[]");
859859
String childPath = index <= 0 ? null : Pair.parseEntry(name.substring(0, index), true).getKey(); // Table-key1-key2...
860860

861861
//判断第一个key,即Table是否存在,如果存在就提取
@@ -877,7 +877,7 @@ public JSONArray onArrayParse(JSONObject request, String parentPath, String name
877877
JSONObject parent;
878878
//生成size个
879879
for (int i = 0; i < (isSubquery ? 1 : size); i++) {
880-
parent = onObjectParse(request, path, "" + i, config.setType(SQLConfig.TYPE_ITEM).setPosition(i), isSubquery);
880+
parent = onObjectParse(request, isSubquery ? parentPath : path, isSubquery ? name : "" + i, config.setType(SQLConfig.TYPE_ITEM).setPosition(i), isSubquery);
881881
if (parent == null || parent.isEmpty()) {
882882
break;
883883
}

0 commit comments

Comments
 (0)