From f05835378a37ca3f30e14bebe6e4463950622ea7 Mon Sep 17 00:00:00 2001 From: TommyLemon Date: Sun, 16 Jun 2024 19:22:15 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=94=AF=E6=8C=81=20key[]:{?= =?UTF-8?q?=20query:2=20=E6=88=96=20query:"All"=20}=20=E9=BB=98=E8=AE=A4?= =?UTF-8?q?=E8=BF=94=E5=9B=9E=E5=88=97=E8=A1=A8=E5=88=86=E9=A1=B5=E4=BF=A1?= =?UTF-8?q?=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/apijson/orm/AbstractObjectParser.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/APIJSONORM/src/main/java/apijson/orm/AbstractObjectParser.java b/APIJSONORM/src/main/java/apijson/orm/AbstractObjectParser.java index e6442013..6b169235 100755 --- a/APIJSONORM/src/main/java/apijson/orm/AbstractObjectParser.java +++ b/APIJSONORM/src/main/java/apijson/orm/AbstractObjectParser.java @@ -27,6 +27,7 @@ import java.util.Map.Entry; import static apijson.JSONObject.KEY_COMBINE; import static apijson.JSONObject.KEY_DROP; import static apijson.JSONObject.KEY_TRY; +import static apijson.JSONRequest.KEY_QUERY; import static apijson.RequestMethod.POST; import static apijson.RequestMethod.PUT; import static apijson.orm.SQLConfig.TYPE_ITEM; @@ -555,8 +556,22 @@ public abstract class AbstractObjectParser implements ObjectPa } } + String query = value.getString(KEY_QUERY); child = parser.onArrayParse(value, path, key, isSubquery); isEmpty = child == null || ((JSONArray) child).isEmpty(); + + if (isEmpty == false && ("2".equals(query) || "ALL".equals(query))) { + String infoKey = JSONResponse.formatArrayKey(key) + "Info"; + if (request.containsKey("total@") == false && request.containsKey(infoKey + "@") == false) { + // onParse("total@", "/" + key + "/total"); + // onParse(infoKey + "@", "/" + key + "/info"); + // 替换为以下性能更好、对流程干扰最小的方式: + String totalPath = AbstractParser.getValuePath(type == TYPE_ITEM ? path : parentPath, "/" + key + "/total"); + String infoPath = AbstractParser.getValuePath(type == TYPE_ITEM ? path : parentPath, "/" + key + "/info"); + response.put("total", onReferenceParse(totalPath)); + response.put(infoKey, onReferenceParse(infoPath)); + } + } } else { //APIJSON Object boolean isTableKey = JSONRequest.isTableKey(Pair.parseEntry(key, true).getKey());