Skip to content

Commit 0093589

Browse files
committed
key[]:{ query:2 或 query:"All" } 解决列表数据为空不返回列表分页信息
1 parent 09a60dc commit 0093589

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -560,16 +560,18 @@ public JSON onChildParse(int index, String key, JSONObject value) throws Excepti
560560
child = parser.onArrayParse(value, path, key, isSubquery);
561561
isEmpty = child == null || ((JSONArray) child).isEmpty();
562562

563-
if (isEmpty == false && ("2".equals(query) || "ALL".equals(query))) {
563+
if ("2".equals(query) || "ALL".equals(query)) { // 不判断 isEmpty,因为分页数据可能只是某页没有
564564
String totalKey = JSONResponse.formatArrayKey(key) + "Total";
565565
String infoKey = JSONResponse.formatArrayKey(key) + "Info";
566566
if ((request.containsKey(totalKey) || request.containsKey(infoKey)
567567
|| request.containsKey(totalKey + "@") || request.containsKey(infoKey + "@")) == false) {
568568
// onParse("total@", "/" + key + "/total");
569569
// onParse(infoKey + "@", "/" + key + "/info");
570570
// 替换为以下性能更好、对流程干扰最小的方式:
571-
String totalPath = AbstractParser.getValuePath(type == TYPE_ITEM ? path : parentPath, "/" + key + "/total");
572-
String infoPath = AbstractParser.getValuePath(type == TYPE_ITEM ? path : parentPath, "/" + key + "/info");
571+
572+
String keyPath = AbstractParser.getValuePath(type == TYPE_ITEM ? path : parentPath, "/" + key);
573+
String totalPath = keyPath + "/total";
574+
String infoPath = keyPath + "/info";
573575
response.put(totalKey, onReferenceParse(totalPath));
574576
response.put(infoKey, onReferenceParse(infoPath));
575577
}

0 commit comments

Comments
 (0)