Skip to content

Commit 58518f3

Browse files
committed
Server:同步eclipse版至idea版
1 parent 97db6c2 commit 58518f3

1 file changed

Lines changed: 14 additions & 11 deletions

File tree

  • APIJSON(Server)/APIJSON(Idea)/src/main/java/zuo/biao/apijson/server

APIJSON(Server)/APIJSON(Idea)/src/main/java/zuo/biao/apijson/server/Parser.java

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -523,18 +523,18 @@ && isInRelationMap(path) == false) {
523523

524524
if (value instanceof JSONObject) {//JSONObject,往下一级提取
525525
if (isArrayKey(key)) {//APIJSON Array
526-
result = getArray(path, parentConfig, key, (JSONObject) value);
526+
result = getArray(path, key, (JSONObject) value);
527527
} else {//APIJSON Object
528528
result = getObject(path, isFirst && isArrayChild //以第0个JSONObject为准
529529
? parentConfig : null, key, (JSONObject) value);
530-
530+
531531
//如果第0个都为空,那后面的也都无意义了。
532532
if (isFirst && isArrayChild && (result == null || result.isEmpty())) {
533533
Log.d(TAG, "getObject isFirst && isArrayChild"
534534
+ " && (result == null || result.isEmpty()) >> return null;");
535535
return null;
536536
}
537-
537+
538538
isFirst = false;//[]里第一个不能为[]
539539
}
540540
Log.i(TAG, "getObject key = " + key + "; result = " + result);
@@ -721,14 +721,12 @@ && isInRelationMap(path) == false) {
721721

722722
/**获取对象数组,该对象数组处于parentObject内
723723
* @param parentPath parentObject的路径
724-
* @param parentConfig 对子object的SQL查询配置,需要传两个层级
725724
* @param name parentObject的key
726725
* @param request parentObject的value
727726
* @return 转为JSONArray不可行,因为会和被当成条件的key:JSONArray冲突。好像一般也就key{}:JSONArray用到??
728727
* @throws Exception
729728
*/
730-
private JSONObject getArray(String parentPath, QueryConfig parentConfig, String name
731-
, final JSONObject request) throws Exception {
729+
private JSONObject getArray(String parentPath, String name, JSONObject request) throws Exception {
732730
Log.i(TAG, "\n\n\n getArray parentPath = " + parentPath
733731
+ "; name = " + name + "; request = " + JSON.toJSONString(request));
734732
if (isHeadMethod(requestMethod, true)) {
@@ -743,6 +741,7 @@ private JSONObject getArray(String parentPath, QueryConfig parentConfig, String
743741

744742
count = request.getIntValue(JSONRequest.KEY_COUNT);
745743
page = request.getIntValue(JSONRequest.KEY_PAGE);
744+
746745
request.remove(JSONRequest.KEY_COUNT);
747746
request.remove(JSONRequest.KEY_PAGE);
748747

@@ -752,8 +751,8 @@ private JSONObject getArray(String parentPath, QueryConfig parentConfig, String
752751

753752
//最好先获取第一个table的所有项(where条件),填充一个列表?
754753
Set<String> set = new LinkedHashSet<>(request.keySet());
755-
if (count <= 0 || count > 5) {//5以下不优化长度
756-
if(parseRelation == false && set != null) {
754+
if(parseRelation == false && set != null) {
755+
if (count <= 0 || count > 5) {//5以下不优化长度
757756
String table;
758757
Object value;
759758
for (String key : set) {
@@ -778,7 +777,7 @@ private JSONObject getArray(String parentPath, QueryConfig parentConfig, String
778777

779778
QueryConfig config = new QueryConfig(requestMethod, count, page);
780779

781-
780+
782781
JSONObject transferredRequest = new JSONObject(true);
783782

784783
JSONObject parent = null;
@@ -808,7 +807,7 @@ private JSONObject getArray(String parentPath, QueryConfig parentConfig, String
808807
config.setPosition(Integer.valueOf(0 + StringUtil.getNumber(key, true)));
809808
isArrayKey = isArrayKey(key);
810809
if (isArrayKey) {//json array
811-
result = getArray(path, config, key, (JSONObject) value);
810+
result = getArray(path, key, (JSONObject) value);
812811
} else {//json object
813812
result = getObject(path, config, key, (JSONObject) value);
814813
}
@@ -826,6 +825,10 @@ private JSONObject getArray(String parentPath, QueryConfig parentConfig, String
826825
}
827826
}
828827

828+
//解决[]:{Comment[]:{...}}内层count,page丢失
829+
request.put(JSONRequest.KEY_COUNT, count);
830+
request.put(JSONRequest.KEY_PAGE, page);
831+
829832
Log.i(TAG, "getArray return " + JSON.toJSONString(transferredRequest) + "\n>>>>>>>>>>>>>>>\n\n\n");
830833

831834
return transferredRequest;
@@ -834,7 +837,7 @@ private JSONObject getArray(String parentPath, QueryConfig parentConfig, String
834837
/**估计最大总数,去掉value中所有依赖引用.
835838
* TODO 返回一个{"total":10, name:value}更好,省去了之后的parseRelation
836839
* @param path
837-
* @param name
840+
* @param table
838841
* @param value
839842
* @return
840843
* @throws Exception

0 commit comments

Comments
 (0)