Skip to content

Commit d6ea489

Browse files
committed
Server:优化Pair并解决Table:alias:{}不能正常获取到值
1 parent 1f3af8b commit d6ea489

File tree

2 files changed

+23
-23
lines changed

2 files changed

+23
-23
lines changed

APIJSON(Server)/APIJSON(Eclipse_JEE)/src/main/java/zuo/biao/apijson/server/Pair.java

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -88,44 +88,44 @@ public static String toPairString(Class<?> type, Object value) {
8888
}
8989

9090
/**
91-
* leftIsKey = true;
91+
* isRightValueDefault = false;
9292
* "key":null不应该出现?因为FastJSON内默认不存null
93-
* @param pair left:right
94-
* @param leftIsKey true-左边为key,当pair不包含 : 时默认整个pair为value;false-相反
93+
* @param pair leftKey:rightValue
9594
* @return {@link #parseEntry(String, boolean)}
9695
*/
9796
public static Entry<String, String> parseEntry(String pair) {
98-
return parseEntry(pair, true);
97+
return parseEntry(pair, false);
9998
}
10099
/**
101-
* leftIsKey = true;
100+
* isRightValueDefault = false;
102101
* "key":null不应该出现?因为FastJSON内默认不存null
103-
* @param pair left:right
104-
* @param leftIsKey true-左边为key,当pair不包含 : 时默认整个pair为value;false-相反
102+
* @param pair leftKey:rightValue
103+
* @param isRightValueDefault 右边值缺省,当pair不包含 : 时默认整个pair为leftKey;false-相反
105104
* @return {@link #parseEntry(String, boolean, String)}
106105
*/
107-
public static Entry<String, String> parseEntry(String pair, boolean isLeftDefault) {
108-
return parseEntry(pair, isLeftDefault, null);
106+
public static Entry<String, String> parseEntry(String pair, boolean isRightValueDefault) {
107+
return parseEntry(pair, isRightValueDefault, null);
109108
}
110109
/**
111110
* "key":null不应该出现?因为FastJSON内默认不存null
112-
* @param pair left:right
113-
* @param leftIsKey true-左边为key,当pair不包含 : 时默认整个pair为value;false-相反
114-
* @param defaultKey key默认值
111+
* @param pair leftKey:rightValue
112+
* @param isRightValueDefault 右边值缺省,当pair不包含 : 时默认整个pair为leftKey;false-相反
113+
* @param defaultKey 缺省值
115114
* @return @NonNull
116115
*/
117-
public static Entry<String, String> parseEntry(String pair, boolean leftIsKey, String defaultKey) {
116+
public static Entry<String, String> parseEntry(String pair, boolean isRightValueDefault, String defaultValue) {
118117
pair = StringUtil.getString(pair);//让客户端去掉所有空格 getNoBlankString(pair);
119118
Entry<String, String> entry = new Entry<String, String>();
120119
if (pair.isEmpty() == false) {
121120
int index = pair.indexOf(":");
122-
if (leftIsKey) {
123-
entry.setKey(index < 0 ? defaultKey : pair.substring(0, index));
124-
entry.setValue(pair.substring(index + 1, pair.length()));
121+
if (index < 0) {
122+
entry.setKey(isRightValueDefault ? pair : defaultValue);
123+
entry.setValue(isRightValueDefault ? defaultValue : pair);
125124
} else {
126-
entry.setValue(index < 0 ? defaultKey : pair.substring(0, index));
127-
entry.setKey(pair.substring(index + 1, pair.length()));
125+
entry.setKey(pair.substring(0, index));
126+
entry.setValue(pair.substring(index + 1, pair.length()));
128127
}
128+
129129
}
130130
return entry;
131131
}
@@ -134,7 +134,7 @@ public static Entry<String, String> parseEntry(String pair, boolean leftIsKey, S
134134
* @return
135135
*/
136136
public static Entry<String, String> parseVariableEntry(String pair) {
137-
return parseEntry(pair, true, Object.class.getSimpleName());
137+
return parseEntry(pair, false, Object.class.getSimpleName());
138138
}
139139
/**
140140
* @param pair

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,7 @@ && isInRelationMap(path) == false) {
495495
}
496496

497497
boolean nameIsNumber = StringUtil.isNumer(name);
498-
String table = Pair.parseEntry(name).getValue();
498+
String table = Pair.parseEntry(name, true).getKey();
499499
Log.d(TAG, "getObject table = " + table);
500500

501501
QueryConfig config = nameIsNumber ? parentConfig : null;
@@ -623,7 +623,7 @@ && isInRelationMap(path) == false) {
623623
transferredRequest.put(replaceKey, target);
624624
}
625625

626-
// removeRelation(getPath(path, replaceKey));
626+
//还要isInRelationMap(path)判断 removeRelation(getPath(path, replaceKey));
627627
updateRelation(path, getAbsPath(path, replaceKey));//request结构已改变,需要更新依赖关系
628628
} else {
629629
//先尝试获取
@@ -870,7 +870,7 @@ public int estimateMaxCount(String path, String name, JSONObject value) throws E
870870
}
871871
}
872872

873-
name = Pair.parseEntry(name).getValue();
873+
name = Pair.parseEntry(name, true).getKey();
874874
JSONObject response = new Parser(RequestMethod.HEAD).parseResponse(new JSONRequest(name, request));
875875
if (response != null) {
876876
response = response.getJSONObject(name);
@@ -1167,7 +1167,7 @@ public static String getRealKey(RequestMethod method, String originKey, boolean
11671167

11681168
//"User:toUser":User转换"toUser":User, User为查询同名Table得到的JSONObject。交给客户端处理更好?不,查询就得截取
11691169
if (isTableKey) {//不允许在column key中使用Type:key形式
1170-
key = Pair.parseEntry(key, false).getKey();//table以左边为准
1170+
key = Pair.parseEntry(key, true).getKey();//table以左边为准
11711171
} else {
11721172
key = Pair.parseEntry(key).getValue();//column以右边为准
11731173
}

0 commit comments

Comments
 (0)