Skip to content

Commit f058353

Browse files
committed
新增支持 key[]:{ query:2 或 query:"All" } 默认返回列表分页信息
1 parent 76fc227 commit f058353

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import static apijson.JSONObject.KEY_COMBINE;
2828
import static apijson.JSONObject.KEY_DROP;
2929
import static apijson.JSONObject.KEY_TRY;
30+
import static apijson.JSONRequest.KEY_QUERY;
3031
import static apijson.RequestMethod.POST;
3132
import static apijson.RequestMethod.PUT;
3233
import static apijson.orm.SQLConfig.TYPE_ITEM;
@@ -555,8 +556,22 @@ public JSON onChildParse(int index, String key, JSONObject value) throws Excepti
555556
}
556557
}
557558

559+
String query = value.getString(KEY_QUERY);
558560
child = parser.onArrayParse(value, path, key, isSubquery);
559561
isEmpty = child == null || ((JSONArray) child).isEmpty();
562+
563+
if (isEmpty == false && ("2".equals(query) || "ALL".equals(query))) {
564+
String infoKey = JSONResponse.formatArrayKey(key) + "Info";
565+
if (request.containsKey("total@") == false && request.containsKey(infoKey + "@") == false) {
566+
// onParse("total@", "/" + key + "/total");
567+
// onParse(infoKey + "@", "/" + key + "/info");
568+
// 替换为以下性能更好、对流程干扰最小的方式:
569+
String totalPath = AbstractParser.getValuePath(type == TYPE_ITEM ? path : parentPath, "/" + key + "/total");
570+
String infoPath = AbstractParser.getValuePath(type == TYPE_ITEM ? path : parentPath, "/" + key + "/info");
571+
response.put("total", onReferenceParse(totalPath));
572+
response.put(infoKey, onReferenceParse(infoPath));
573+
}
574+
}
560575
}
561576
else { //APIJSON Object
562577
boolean isTableKey = JSONRequest.isTableKey(Pair.parseEntry(key, true).getKey());

0 commit comments

Comments
 (0)