From 790f8c5c1accf612da2080651e8b09391951f1e9 Mon Sep 17 00:00:00 2001 From: TommyLemon Date: Sun, 22 Oct 2023 22:14:48 +0800 Subject: [PATCH] =?UTF-8?q?=E5=85=A8=E8=83=BD=20CRUD:=20"@gets":=20{=20"Us?= =?UTF-8?q?er":""=20//=20=E7=A9=BA=E5=AD=97=E7=AC=A6=E4=B8=B2=E8=BD=AC?= =?UTF-8?q?=E4=B8=BA=E4=B8=8E=20key=20=E5=90=8C=E5=90=8D=E5=80=BC=20User?= =?UTF-8?q?=20}=EF=BC=8C"@put":=20{=20"Moment":{}=20//=20=E8=87=AA?= =?UTF-8?q?=E5=8A=A8=E5=8A=A0=20"tag":"Moment"=20}=EF=BC=8C@post:"Comment[?= =?UTF-8?q?]"=20=E8=87=AA=E5=8A=A8=E8=BD=AC=E4=B8=BA=20"@post":{=20"Commen?= =?UTF-8?q?t[]":"Comment:[]"=20}?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/apijson/orm/AbstractParser.java | 22 ++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/APIJSONORM/src/main/java/apijson/orm/AbstractParser.java b/APIJSONORM/src/main/java/apijson/orm/AbstractParser.java index c552888b..81434a31 100755 --- a/APIJSONORM/src/main/java/apijson/orm/AbstractParser.java +++ b/APIJSONORM/src/main/java/apijson/orm/AbstractParser.java @@ -2190,9 +2190,10 @@ public abstract class AbstractParser implements Parser, Par throw new IllegalArgumentException("对象名重复,请添加别名区分 ! 重复对象名为: " + key); } + boolean isPost = apijson.orm.JSONRequest.KEY_POST.equals(key); // @post、@get 等 RequestMethod try { - RequestMethod keyMethod = apijson.orm.JSONRequest.KEY_METHOD_ENUM_MAP.get(key); + RequestMethod keyMethod = isPost ? RequestMethod.POST : JSONRequest.KEY_METHOD_ENUM_MAP.get(key); if (keyMethod != null) { // 如果不匹配,异常不处理即可 removeTmpKeys.add(key); @@ -2209,7 +2210,9 @@ public abstract class AbstractParser implements Parser, Par if (obj.containsKey(tbl)) { throw new ConflictException(key + ": value 中 " + tbl + " 已经存在,不能重复!"); } - obj.put(tbl, new JSONObject(true)); + + obj.put(tbl, isPost && JSONRequest.isTableArray(tbl) + ? tbl.substring(0, tbl.length() - 2) + ":[]" : ""); } } } @@ -2234,15 +2237,16 @@ public abstract class AbstractParser implements Parser, Par JSONObject objAttrJson = objVal instanceof JSONObject ? obj.getJSONObject(objKey) : null; if (objAttrJson == null) { if (objVal instanceof String) { - objAttrMap.put(JSONRequest.KEY_TAG, objVal); + objAttrMap.put(JSONRequest.KEY_TAG, "".equals(objVal) ? objKey : objVal); } else { throw new IllegalArgumentException(key + ": { " + objKey + ": value 中 value 类型错误,只能是 String 或 JSONObject {} !"); } } else { - Set> objSet = objAttrJson == null ? new HashSet<>() : objAttrJson.entrySet(); + Set> objSet = objAttrJson.entrySet(); + boolean hasTag = false; for (Entry entry : objSet) { String objAttrKey = entry == null ? null : entry.getKey(); if (objAttrKey == null) { @@ -2255,13 +2259,21 @@ public abstract class AbstractParser implements Parser, Par case apijson.JSONObject.KEY_DATABASE: case JSONRequest.KEY_VERSION: case apijson.JSONObject.KEY_ROLE: + objAttrMap.put(objAttrKey, entry.getValue()); + break; case JSONRequest.KEY_TAG: + hasTag = true; objAttrMap.put(objAttrKey, entry.getValue()); break; default: break; } } + + if (hasTag == false) { + objAttrMap.put(JSONRequest.KEY_TAG, isPost && JSONRequest.isTableArray(objKey) + ? objKey.substring(0, objKey.length() - 2) + ":[]" : objKey); + } } } continue; @@ -2376,7 +2388,7 @@ public abstract class AbstractParser implements Parser, Par } } catch (Exception e) { e.printStackTrace(); - throw new Exception(e); + throw new Exception(e); // 包装一层只是为了打印日志?看起来没必要 } }