Skip to content

Commit 7ee8418

Browse files
committed
Server:解决获取Object失败导致不能获取里面JSONObject
1 parent f453889 commit 7ee8418

1 file changed

Lines changed: 18 additions & 10 deletions

File tree

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

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

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import java.util.List;
2323
import java.util.Map;
2424
import java.util.Set;
25+
import java.util.regex.Pattern;
2526

2627
import org.springframework.web.bind.annotation.RequestMethod;
2728

@@ -210,7 +211,7 @@ public static JSONObject getCorrectRequest(RequestMethod method, JSONObject requ
210211
object = object.getJSONObject("structure");//解决返回值套了一层 "structure":{}
211212

212213
JSONObject target = null;
213-
if (isObjectKey(tag) && object.containsKey(tag) == false) {//tag是table名
214+
if (isTableKey(tag) && object.containsKey(tag) == false) {//tag是table名
214215
target = new JSONObject(true);
215216
target.put(tag, object);
216217
} else {
@@ -240,9 +241,9 @@ public static JSONObject fillTarget(RequestMethod method
240241
System.out.println(TAG + "filterTarget target == null || request == null >> return null;");
241242
return null;
242243
}
243-
// if (method == null) {
244-
// method = RequestMethod.GET;
245-
// }
244+
// if (method == null) {
245+
// method = RequestMethod.GET;
246+
// }
246247

247248
/**方法三:遍历request,transferredRequest只添加target所包含的object
248249
* ,且移除target中DISALLOW_COLUMNS,期间判断NECESSARY_COLUMNS是否都有
@@ -405,7 +406,7 @@ private JSONObject getObject(String parentPath, final QueryConfig parentConfig,
405406
}
406407
}
407408

408-
if (containRelation == false && isObjectKey(name)) {
409+
if (containRelation == false && isTableKey(name)) {//提高性能 isObjectKey(name)) {
409410
if (parseRelation == false || isInRelationMap(path)) {//避免覆盖原来已经获取的
410411
// relationMap.remove(path);
411412
QueryConfig config2 = newQueryConfig(name, transferredRequest);
@@ -415,9 +416,12 @@ private JSONObject getObject(String parentPath, final QueryConfig parentConfig,
415416
.setPosition(parentConfig.getPosition());//避免position > 0的object获取不到
416417
}
417418

418-
transferredRequest = getSQLObject(config2);
419-
if (parseRelation) {
420-
putValueByPath(path, transferredRequest);//解决获取关联数据时requestObject里不存在需要的关联数据
419+
JSONObject result = getSQLObject(config2);
420+
if (result != null && result.isEmpty() == false) {//解决获取失败导致不能获取里面JSONObject
421+
transferredRequest = result;
422+
if (parseRelation) {
423+
putValueByPath(path, transferredRequest);//解决获取关联数据时requestObject里不存在需要的关联数据
424+
}
421425
}
422426
}
423427
}
@@ -703,9 +707,13 @@ public static boolean isObject(String json) {
703707
return JSON.parseObject(json) != null;//json.startsWith("{") && json.endsWith("}");
704708
}
705709

706-
public static boolean isObjectKey(String key) {
710+
private static final Pattern bigAlphaPattern = Pattern.compile("[A-Z]");
711+
712+
public static boolean isTableKey(String key) {
707713
key = StringUtil.getString(key);
708-
return StringUtil.isNotEmpty(key, false) && isArrayKey(key) == false && StringUtil.isAlpha(key.substring(0, 1));
714+
715+
return StringUtil.isNotEmpty(key, false) && isArrayKey(key) == false
716+
&& bigAlphaPattern.matcher(key.substring(0, 1)).matches();
709717
}
710718
public static boolean isArrayKey(String key) {
711719
return key != null && key.endsWith("[]");

0 commit comments

Comments
 (0)