userList2 = JSON.parseArray(item.getString("User[]"), User.class);
if (userList2 == null) {
- userList2 = new JSONArray();
+ userList2 = new ArrayList<>();
}
- JSONObject item2;
+ User item2;
for (int i2 = 0; i2 < userList2.size(); i2 ++) {
- item2 = userList2.getJSONObject(i2);
+ item2 = userList2.get(i2);
if (item2 == null) {
continue;
}
System.out.println("\nitem2 = userList2[" + i2 + "] = \n" + item2 + "\n\n");
- //TODO 你的代码
+ // TODO 你的代码
- long id = item2.getLongValue("id");
+ long id = item2.getId();
System.out.println("item2.id = " + id);
- String name = item2.getString("name");
+ String name = item2.getName();
System.out.println("item2.name = " + name);
}
- } //User[]>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+ } //User[] >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
- { //[]<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+ { // [] <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
JSONArray list2 = item.getJSONArray("[]");
if (list2 == null) {
list2 = new JSONArray();
@@ -422,71 +491,56 @@ public static void response(String resultJson) {
continue;
}
System.out.println("\nitem2 = list2[" + i2 + "] = \n" + item2 + "\n\n");
- //TODO 你的代码
+ // TODO 你的代码
- { //Comment<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
- JSONObject comment = item2.getJSONObject("Comment");
+ { // Comment <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+ Comment comment = item2.getObject("Comment", Comment.class);
if (comment == null) {
- comment = new JSONObject();
+ comment = new Comment();
}
- long id = comment.getLongValue("id");
+ long id = comment.getId();
System.out.println("comment.id = " + id);
- long toId = comment.getLongValue("toId");
+ long toId = comment.getToId();
System.out.println("comment.toId = " + toId);
- long userId = comment.getLongValue("userId");
+ long userId = comment.getUserId();
System.out.println("comment.userId = " + userId);
- long momentId = comment.getLongValue("momentId");
+ long momentId = comment.getMomentId();
System.out.println("comment.momentId = " + momentId);
- String date = comment.getString("date");
+ Long date = comment.getDate();
System.out.println("comment.date = " + date);
- String content = comment.getString("content");
+ String content = comment.getContent();
System.out.println("comment.content = " + content);
- } //Comment>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+ } //Comment >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
- { //User<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
- JSONObject user = item2.getJSONObject("User");
+ { // User <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+ User user = item2.getObject("User", User.class);
if (user == null) {
- user = new JSONObject();
+ user = new User();
}
- long id = user.getLongValue("id");
+ long id = user.getId();
System.out.println("user.id = " + id);
- String name = user.getString("name");
+ String name = user.getName();
System.out.println("user.name = " + name);
- } //User>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+ } //User >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
}
- } //[]>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-
- }
- } //[]>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-
+ } //[] >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
- { //list<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
- JSONArray list = response.getJSONArray("list");
- if (list == null) {
- list = new JSONArray();
}
+ } //[] >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
- Object item;
- for (int i = 0; i < list.size(); i ++) {
- item = list.get(i);
- if (item == null) {
- continue;
- }
- System.out.println("\nitem = list[" + i + "] = \n" + item + "\n\n");
- //TODO 你的代码
-
- }
- } //list>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-
+ boolean ok = response.getBooleanValue("ok");
+ System.out.println("response.ok = " + ok);
int code = response.getIntValue("code");
System.out.println("response.code = " + code);
String msg = response.getString("msg");
System.out.println("response.msg = " + msg);
+
}
+
}
From 566f40e6fc256bdf7b3ac278f8ddfce5d8ec26d2 Mon Sep 17 00:00:00 2001
From: TommyLemon <1184482681@qq.com>
Date: Tue, 28 Apr 2020 17:26:42 +0800
Subject: [PATCH 0033/1327] =?UTF-8?q?Server=EF=BC=9A=E5=88=A0=E9=99=A4?=
=?UTF-8?q?=E6=B3=A8=E9=87=8A=E4=B8=AD=E5=A4=9A=E4=BD=99=E7=9A=84=E4=B8=80?=
=?UTF-8?q?=E4=B8=AA=E6=8B=AC=E5=8F=B7?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../APIJSONORM/src/main/java/apijson/orm/Operation.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/APIJSON-Java-Server/APIJSONORM/src/main/java/apijson/orm/Operation.java b/APIJSON-Java-Server/APIJSONORM/src/main/java/apijson/orm/Operation.java
index b4b9e13ca..c8e7f7f20 100755
--- a/APIJSON-Java-Server/APIJSONORM/src/main/java/apijson/orm/Operation.java
+++ b/APIJSON-Java-Server/APIJSONORM/src/main/java/apijson/orm/Operation.java
@@ -34,7 +34,7 @@ public enum Operation {
/**TODO 是否应该把数组类型写成 BOOLEANS, NUMBERS 等复数单词,以便抽取 enum ?扩展用 VERIFY 或 INSERT/UPDATE 远程函数等
* 验证是否符合预设的类型:
- * BOOLEAN, NUMBER, DECIMAL, STRING, URL, DATE, TIME, DATETIME, OBJECT, ARRAY ]
+ * BOOLEAN, NUMBER, DECIMAL, STRING, URL, DATE, TIME, DATETIME, OBJECT, ARRAY
* 或它们的数组
* BOOLEAN[], NUMBER[], DECIMAL[], STRING[], URL[], DATE[], TIME[], DATETIME[], OBJECT[], ARRAY[]
* 结构是
From b7818ff493283b835691861034e8a1a2df2ebc26 Mon Sep 17 00:00:00 2001
From: TommyLemon <1184482681@qq.com>
Date: Tue, 28 Apr 2020 17:44:31 +0800
Subject: [PATCH 0034/1327] Update README.md
---
README.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/README.md b/README.md
index 2397b3524..45f8f6071 100644
--- a/README.md
+++ b/README.md
@@ -101,7 +101,7 @@ APIJSON是一种专为API而生的 JSON网络传输协议 以及 基于这套协

- 一图胜前言 - 部分基础功能概览
+ 一图胜千言 - 部分基础功能概览
From 5ebfa8df72928ec44f7df210120e4aa0c508dbd7 Mon Sep 17 00:00:00 2001
From: TommyLemon <1184482681@qq.com>
Date: Sat, 2 May 2020 02:31:45 +0800
Subject: [PATCH 0035/1327] =?UTF-8?q?Server=EF=BC=9A=E8=B0=83=E6=95=B4=20^?=
=?UTF-8?q?=20SIDE=20JOIN(ANTI=20JOIN)=20=E7=9A=84=E5=AE=9E=E7=8E=B0?=
=?UTF-8?q?=E4=B8=BA=20!=20(A=20&=20B)=EF=BC=8C=E5=92=8C=E5=8E=9F=E6=9D=A5?=
=?UTF-8?q?=E7=9A=84=E5=AE=9E=E7=8E=B0=20(A=20&=20!=20B)=20|=20(B=20&=20!?=
=?UTF-8?q?=20A)=20=E6=9F=A5=E8=AF=A2=E7=BB=93=E6=9E=9C=E4=B8=8D=E4=B8=80?=
=?UTF-8?q?=E8=87=B4=EF=BC=8C=E4=B8=80=E8=88=AC=E6=95=B0=E9=87=8F=E6=9B=B4?=
=?UTF-8?q?=E5=A4=9A=EF=BC=81?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../java/apijson/orm/AbstractSQLConfig.java | 37 ++++++++-----------
1 file changed, 16 insertions(+), 21 deletions(-)
diff --git a/APIJSON-Java-Server/APIJSONORM/src/main/java/apijson/orm/AbstractSQLConfig.java b/APIJSON-Java-Server/APIJSONORM/src/main/java/apijson/orm/AbstractSQLConfig.java
index 349ecfb8b..d8aecdee4 100755
--- a/APIJSON-Java-Server/APIJSONORM/src/main/java/apijson/orm/AbstractSQLConfig.java
+++ b/APIJSON-Java-Server/APIJSONORM/src/main/java/apijson/orm/AbstractSQLConfig.java
@@ -1387,36 +1387,31 @@ else if ("!".equals(ce.getKey())) {
newWs += AND;
}
- if ("^".equals(j.getJoinType())) { // (A & ! B) | (B & ! A)
- newWs += " ( ( " + ws + ( StringUtil.isEmpty(ws, true) ? "" : AND + NOT ) + " ( " + js + " ) ) "
- + OR
- + " ( " + js + AND + NOT + " ( " + ws + " ) ) ) ";
-
- newPvl.addAll(pvl);
- newPvl.addAll(jc.getPreparedValueList());
- newPvl.addAll(jc.getPreparedValueList());
- newPvl.addAll(pvl);
+ if ("^".equals(j.getJoinType())) { // ! (A & B)
+ newWs += " ( " + getCondition(
+ true,
+ ( StringUtil.isEmpty(ws, true) ? "" : ws + AND ) + " ( " + js + " ) "
+ ) + " ) ";
}
else {
logic = Logic.getType(j.getJoinType());
- newWs += " ( "
- + getCondition(
- Logic.isNot(logic),
- ws
- + ( StringUtil.isEmpty(ws, true) ? "" : (Logic.isAnd(logic) ? AND : OR) )
- + " ( " + js + " ) "
- )
- + " ) ";
-
- newPvl.addAll(pvl);
- newPvl.addAll(jc.getPreparedValueList());
+ newWs += " ( " + getCondition(
+ Logic.isNot(logic),
+ ( StringUtil.isEmpty(ws, true) ? "" : ws + (Logic.isAnd(logic) ? AND : OR) ) + " ( " + js + " ) "
+ ) + " ) ";
}
+
+ newPvl.addAll(pvl);
+ newPvl.addAll(jc.getPreparedValueList());
changed = true;
break;
default:
- throw new UnsupportedOperationException("join:value 中 value 里的 " + j.getJoinType() + "/" + j.getPath() + "错误!不支持 " + j.getJoinType() + " 等 [@ APP, < LEFT, > RIGHT, | FULL, & INNER, ! OUTTER, ^ SIDE, * CROSS] 之外的JOIN类型 !");
+ throw new UnsupportedOperationException(
+ "join:value 中 value 里的 " + j.getJoinType() + "/" + j.getPath() + "错误!不支持 " + j.getJoinType()
+ + " 等 [@ APP, < LEFT, > RIGHT, | FULL, & INNER, ! OUTTER, ^ SIDE, * CROSS] 之外的JOIN类型 !"
+ );
}
}
From bd96636047dbd3fd5989368e13848762adab0265 Mon Sep 17 00:00:00 2001
From: TommyLemon <1184482681@qq.com>
Date: Sat, 2 May 2020 02:37:16 +0800
Subject: [PATCH 0036/1327] =?UTF-8?q?Revert=20"Server=EF=BC=9A=E8=B0=83?=
=?UTF-8?q?=E6=95=B4=20^=20SIDE=20JOIN(ANTI=20JOIN)=20=E7=9A=84=E5=AE=9E?=
=?UTF-8?q?=E7=8E=B0=E4=B8=BA=20!=20(A=20&=20B)=EF=BC=8C=E5=92=8C=E5=8E=9F?=
=?UTF-8?q?=E6=9D=A5=E7=9A=84=E5=AE=9E=E7=8E=B0=20(A=20&=20!=20B)=20|=20(B?=
=?UTF-8?q?=20&=20!=20A)=20=E6=9F=A5=E8=AF=A2=E7=BB=93=E6=9E=9C=E4=B8=8D?=
=?UTF-8?q?=E4=B8=80=E8=87=B4=EF=BC=8C=E4=B8=80=E8=88=AC=E6=95=B0=E9=87=8F?=
=?UTF-8?q?=E6=9B=B4=E5=A4=9A=EF=BC=81"?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
This reverts commit 5ebfa8df72928ec44f7df210120e4aa0c508dbd7.
---
.../java/apijson/orm/AbstractSQLConfig.java | 37 +++++++++++--------
1 file changed, 21 insertions(+), 16 deletions(-)
diff --git a/APIJSON-Java-Server/APIJSONORM/src/main/java/apijson/orm/AbstractSQLConfig.java b/APIJSON-Java-Server/APIJSONORM/src/main/java/apijson/orm/AbstractSQLConfig.java
index d8aecdee4..349ecfb8b 100755
--- a/APIJSON-Java-Server/APIJSONORM/src/main/java/apijson/orm/AbstractSQLConfig.java
+++ b/APIJSON-Java-Server/APIJSONORM/src/main/java/apijson/orm/AbstractSQLConfig.java
@@ -1387,31 +1387,36 @@ else if ("!".equals(ce.getKey())) {
newWs += AND;
}
- if ("^".equals(j.getJoinType())) { // ! (A & B)
- newWs += " ( " + getCondition(
- true,
- ( StringUtil.isEmpty(ws, true) ? "" : ws + AND ) + " ( " + js + " ) "
- ) + " ) ";
+ if ("^".equals(j.getJoinType())) { // (A & ! B) | (B & ! A)
+ newWs += " ( ( " + ws + ( StringUtil.isEmpty(ws, true) ? "" : AND + NOT ) + " ( " + js + " ) ) "
+ + OR
+ + " ( " + js + AND + NOT + " ( " + ws + " ) ) ) ";
+
+ newPvl.addAll(pvl);
+ newPvl.addAll(jc.getPreparedValueList());
+ newPvl.addAll(jc.getPreparedValueList());
+ newPvl.addAll(pvl);
}
else {
logic = Logic.getType(j.getJoinType());
- newWs += " ( " + getCondition(
- Logic.isNot(logic),
- ( StringUtil.isEmpty(ws, true) ? "" : ws + (Logic.isAnd(logic) ? AND : OR) ) + " ( " + js + " ) "
- ) + " ) ";
+ newWs += " ( "
+ + getCondition(
+ Logic.isNot(logic),
+ ws
+ + ( StringUtil.isEmpty(ws, true) ? "" : (Logic.isAnd(logic) ? AND : OR) )
+ + " ( " + js + " ) "
+ )
+ + " ) ";
+
+ newPvl.addAll(pvl);
+ newPvl.addAll(jc.getPreparedValueList());
}
-
- newPvl.addAll(pvl);
- newPvl.addAll(jc.getPreparedValueList());
changed = true;
break;
default:
- throw new UnsupportedOperationException(
- "join:value 中 value 里的 " + j.getJoinType() + "/" + j.getPath() + "错误!不支持 " + j.getJoinType()
- + " 等 [@ APP, < LEFT, > RIGHT, | FULL, & INNER, ! OUTTER, ^ SIDE, * CROSS] 之外的JOIN类型 !"
- );
+ throw new UnsupportedOperationException("join:value 中 value 里的 " + j.getJoinType() + "/" + j.getPath() + "错误!不支持 " + j.getJoinType() + " 等 [@ APP, < LEFT, > RIGHT, | FULL, & INNER, ! OUTTER, ^ SIDE, * CROSS] 之外的JOIN类型 !");
}
}
From 1eebd7b01ab40ef41e8b4c511edbdc6b2d4f37e4 Mon Sep 17 00:00:00 2001
From: TommyLemon <1184482681@qq.com>
Date: Sat, 2 May 2020 03:02:41 +0800
Subject: [PATCH 0037/1327] =?UTF-8?q?Server=EF=BC=9A=E6=96=B0=E5=A2=9E?=
=?UTF-8?q?=E6=92=A4=E5=9B=9E=20^=20SIDE=20JOIN=20=E4=BF=AE=E6=94=B9?=
=?UTF-8?q?=E7=9A=84=E8=AF=B4=E6=98=8E?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../APIJSONORM/src/main/java/apijson/orm/AbstractSQLConfig.java | 1 +
1 file changed, 1 insertion(+)
diff --git a/APIJSON-Java-Server/APIJSONORM/src/main/java/apijson/orm/AbstractSQLConfig.java b/APIJSON-Java-Server/APIJSONORM/src/main/java/apijson/orm/AbstractSQLConfig.java
index 349ecfb8b..6476ae3d4 100755
--- a/APIJSON-Java-Server/APIJSONORM/src/main/java/apijson/orm/AbstractSQLConfig.java
+++ b/APIJSON-Java-Server/APIJSONORM/src/main/java/apijson/orm/AbstractSQLConfig.java
@@ -1387,6 +1387,7 @@ else if ("!".equals(ce.getKey())) {
newWs += AND;
}
+ //MySQL 因为 NULL 值处理问题,(A & ! B) | (B & ! A) 与 ! (A & B) 返回结果不一样,后者往往更多
if ("^".equals(j.getJoinType())) { // (A & ! B) | (B & ! A)
newWs += " ( ( " + ws + ( StringUtil.isEmpty(ws, true) ? "" : AND + NOT ) + " ( " + js + " ) ) "
+ OR
From 5ef8a5edcb1d52c6e6fab4a974bfd2878e309e12 Mon Sep 17 00:00:00 2001
From: TommyLemon <1184482681@qq.com>
Date: Sat, 2 May 2020 03:03:26 +0800
Subject: [PATCH 0038/1327] =?UTF-8?q?Server=EF=BC=9A=E5=BC=95=E5=85=A5=20U?=
=?UTF-8?q?nitAuto=20=E8=87=AA=E5=8A=A8=E5=8C=96=E5=8D=95=E5=85=83?=
=?UTF-8?q?=E6=B5=8B=E8=AF=95=E5=B7=A5=E5=85=B7=20MethodUtil=20=E5=8F=8A?=
=?UTF-8?q?=E7=9B=B8=E5=85=B3=E6=8E=A5=E5=8F=A3=E5=92=8C=E8=BF=9C=E7=A8=8B?=
=?UTF-8?q?=E5=87=BD=E6=95=B0?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../apijson/framework/APIJSONController.java | 9 +
.../framework/APIJSONFunctionParser.java | 145 +++
.../java/apijson/framework/MethodUtil.java | 862 ++++++++++++++++++
3 files changed, 1016 insertions(+)
create mode 100644 APIJSON-Java-Server/APIJSONFramework/src/main/java/apijson/framework/MethodUtil.java
diff --git a/APIJSON-Java-Server/APIJSONFramework/src/main/java/apijson/framework/APIJSONController.java b/APIJSON-Java-Server/APIJSONFramework/src/main/java/apijson/framework/APIJSONController.java
index 5dd45951a..73b23bca3 100755
--- a/APIJSON-Java-Server/APIJSONFramework/src/main/java/apijson/framework/APIJSONController.java
+++ b/APIJSON-Java-Server/APIJSONFramework/src/main/java/apijson/framework/APIJSONController.java
@@ -34,6 +34,7 @@
import javax.servlet.http.HttpSession;
+import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import apijson.Log;
@@ -223,4 +224,12 @@ public Object logout(@NotNull HttpSession session) {
}
+ public JSONObject invokeMethod(String request) {
+ return MethodUtil.invokeMethod(request);
+ }
+
+ public JSONObject listMethod(String request) {
+ return MethodUtil.listMethod(request);
+ }
+
}
diff --git a/APIJSON-Java-Server/APIJSONFramework/src/main/java/apijson/framework/APIJSONFunctionParser.java b/APIJSON-Java-Server/APIJSONFramework/src/main/java/apijson/framework/APIJSONFunctionParser.java
index 5d924262b..1f045c455 100755
--- a/APIJSON-Java-Server/APIJSONFramework/src/main/java/apijson/framework/APIJSONFunctionParser.java
+++ b/APIJSON-Java-Server/APIJSONFramework/src/main/java/apijson/framework/APIJSONFunctionParser.java
@@ -16,6 +16,7 @@
import static apijson.framework.APIJSONConstant.FUNCTION_;
+import java.io.IOException;
import java.rmi.ServerException;
import java.util.ArrayList;
import java.util.Arrays;
@@ -33,6 +34,7 @@
import apijson.RequestMethod;
import apijson.RequestRole;
import apijson.StringUtil;
+import apijson.framework.MethodUtil.Argument;
import apijson.orm.AbstractFunctionParser;
import apijson.orm.JSONRequest;
import apijson.orm.ParserCreator;
@@ -292,6 +294,149 @@ public Object verifyAccess(@NotNull JSONObject request) throws Exception {
+ /**获取方法参数的定义
+ * @param request
+ * @return
+ * @throws IOException
+ * @throws ClassNotFoundException
+ * @throws IllegalArgumentException
+ */
+ public String getMethodArguments(@NotNull JSONObject request) throws IllegalArgumentException, ClassNotFoundException, IOException {
+ return getMethodArguments(request, "methodArgs");
+ }
+ /**获取方法参数的定义
+ * @param request
+ * @param requestKey
+ * @param methodArgs
+ * @return
+ * @throws IllegalArgumentException
+ * @throws ClassNotFoundException
+ * @throws IOException
+ */
+ public String getMethodArguments(@NotNull JSONObject request, String methodArgsKey) throws IllegalArgumentException, ClassNotFoundException, IOException {
+ String argsStr = request.getString(methodArgsKey);
+ if (StringUtil.isEmpty(argsStr, true)) {
+ JSONObject obj = request.getJSONObject("request");
+ argsStr = obj == null ? null : obj.getString(methodArgsKey);
+ }
+ List methodArgs = JSON.parseArray(removeComment(argsStr), Argument.class);
+ if (methodArgs == null || methodArgs.isEmpty()) {
+ return "";
+ }
+
+ Class>[] types = new Class>[methodArgs.size()];
+ Object[] args = new Object[methodArgs.size()];
+ MethodUtil.initTypesAndValues(methodArgs, types, args, true);
+
+ String s = "";
+ if (types != null) {
+ String sn;
+ for (int i = 0; i < types.length; i++) {
+ sn = types[i] == null ? null : types[i].getSimpleName();
+ if (sn == null) {
+ sn = Object.class.getSimpleName();
+ }
+
+ if (i > 0) {
+ s += ",";
+ }
+
+ if (MethodUtil.CLASS_MAP.containsKey(sn)) {
+ s += sn;
+ }
+ else {
+ s += types[i].getName();
+ }
+ }
+ }
+ return s;
+ }
+
+
+ /**获取方法的定义
+ * @param request
+ * @return
+ * @throws IOException
+ * @throws ClassNotFoundException
+ * @throws IllegalArgumentException
+ */
+ public String getMethodDefination(@NotNull JSONObject request)
+ throws IllegalArgumentException, ClassNotFoundException, IOException {
+// request.put("arguments", removeComment(request.getString("methodArgs")));
+ return getMethodDefination(request, "method", "arguments", "type", "exceptions", "Java");
+ }
+ /**获取方法的定义
+ * @param request
+ * @param method
+ * @param arguments
+ * @param type
+ * @return method(argType0,argType1...): returnType
+ * @throws IOException
+ * @throws ClassNotFoundException
+ * @throws IllegalArgumentException
+ */
+ public String getMethodDefination(@NotNull JSONObject request, String method, String arguments, String type, String exceptions, String language)
+ throws IllegalArgumentException, ClassNotFoundException, IOException {
+ String n = request.getString(method);
+ if (StringUtil.isEmpty(n, true)) {
+ throw new NullPointerException("getMethodDefination StringUtil.isEmpty(methodArgs, true) !");
+ }
+ String a = request.getString(arguments);
+ String t = request.getString(type);
+ String e = request.getString(exceptions);
+
+ if (language == null) {
+ language = "";
+ }
+ switch (language) {
+ case "TypeScript":
+ return n + "(" + (StringUtil.isEmpty(a, true) ? "" : a) + ")" + (StringUtil.isEmpty(t, true) ? "" : ": " + t) + (StringUtil.isEmpty(e, true) ? "" : " throws " + e);
+ case "Go":
+ return n + "(" + (StringUtil.isEmpty(a, true) ? "" : a ) + ")" + (StringUtil.isEmpty(t, true) ? "" : " " + t) + (StringUtil.isEmpty(e, true) ? "" : " throws " + e);
+ default:
+ //类型可能很长,Eclipse, Idea 代码提示都是类型放后面 return (StringUtil.isEmpty(t, true) ? "" : t + " ") + n + "(" + (StringUtil.isEmpty(a, true) ? "" : a) + ")";
+ return n + "(" + (StringUtil.isEmpty(a, true) ? "" : a) + ")" + (StringUtil.isEmpty(t, true) ? "" : ": " + t) + (StringUtil.isEmpty(e, true) ? "" : " throws " + e);
+ }
+ }
+
+ /**
+ * methodArgs 和 classArgs 都可以带注释
+ */
+ public String getMethodRequest(@NotNull JSONObject request) {
+ String req = request.getString("request");
+ if (StringUtil.isEmpty(req, true) == false) {
+ return req;
+ }
+
+ req = "{";
+ Boolean isStatic = request.getBoolean("static");
+ String methodArgs = request.getString("methodArgs");
+ String classArgs = request.getString("classArgs");
+
+ boolean comma = false;
+ if (isStatic != null && isStatic) {
+ req += "\n \"static\": " + true;
+ comma = true;
+ }
+ if (StringUtil.isEmpty(methodArgs, true) == false) {
+ req += (comma ? "," : "") + "\n \"methodArgs\": " + methodArgs;
+ comma = true;
+ }
+ if (StringUtil.isEmpty(classArgs, true) == false) {
+ req += (comma ? "," : "") + "\n \"classArgs\": " + classArgs;
+ }
+ req += "\n}";
+ return req;
+ }
+
+ // public static JSONObject removeComment(String json) {
+ // return JSON.parseObject(removeComment(json));
+ // }
+ public static String removeComment(String json) {
+ return json == null ? null: json.replaceAll("(//.*)|(/\\*[\\s\\S]*?\\*/)", "");
+ }
+
+
public double plus(@NotNull JSONObject request, String i0, String i1) {
return request.getDoubleValue(i0) + request.getDoubleValue(i1);
diff --git a/APIJSON-Java-Server/APIJSONFramework/src/main/java/apijson/framework/MethodUtil.java b/APIJSON-Java-Server/APIJSONFramework/src/main/java/apijson/framework/MethodUtil.java
new file mode 100644
index 000000000..956827d91
--- /dev/null
+++ b/APIJSON-Java-Server/APIJSONFramework/src/main/java/apijson/framework/MethodUtil.java
@@ -0,0 +1,862 @@
+package apijson.framework;
+
+import java.io.File;
+import java.lang.reflect.Array;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import java.lang.reflect.Type;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Objects;
+import java.util.Set;
+
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import com.alibaba.fastjson.parser.ParserConfig;
+import com.alibaba.fastjson.util.TypeUtils;
+
+public class MethodUtil {
+
+
+ public interface Callback {
+ JSONObject newSuccessResult();
+ JSONObject newErrorResult(Exception e);
+ }
+
+ public static String KEY_CODE = "code";
+ public static String KEY_MSG = "msg";
+
+ public static int CODE_SUCCESS = 200;
+ public static int CODE_SERVER_ERROR = 500;
+ public static String MSG_SUCCESS = "success";
+ public static Callback CALLBACK = new Callback() {
+
+ @Override
+ public JSONObject newSuccessResult() {
+ JSONObject result = new JSONObject(true);
+ result.put(KEY_CODE, CODE_SUCCESS);
+ result.put(KEY_MSG, MSG_SUCCESS);
+ return result;
+ }
+
+ @Override
+ public JSONObject newErrorResult(Exception e) {
+ JSONObject result = new JSONObject(true);
+ result.put(KEY_CODE, CODE_SERVER_ERROR);
+ result.put(KEY_MSG, e.getMessage());
+ return result;
+ }
+ };
+
+ // Map>
+ public static final Map, Map