Skip to content

Commit e5d3c3a

Browse files
committed
Server:新增返回 invoke 后的参数类型和值
1 parent 5ebba07 commit e5d3c3a

File tree

1 file changed

+12
-4
lines changed
  • UnitAuto-Backend/UnitAutoBoot/src/main/java/apijson/demo/server

1 file changed

+12
-4
lines changed

UnitAuto-Backend/UnitAutoBoot/src/main/java/apijson/demo/server/MethodUtil.java

+12-4
Original file line numberDiff line numberDiff line change
@@ -245,12 +245,17 @@ public static JSONObject invokeMethod(JSONObject req, Object instance) {
245245
if (clazz == null) {
246246
throw new ClassNotFoundException("找不到 " + dot2Separator(pkgName) + "/" + clsName + " 对应的类!");
247247
}
248+
248249
if (instance == null && req.getBooleanValue("static") == false) {
249250
instance = getInvokeInstance(clazz, getArgList(req, "classArgs"));
250251
}
251252

253+
JSONObject ir = getInvokeResult(clazz, instance, methodName, getArgList(req, "methodArgs"));
254+
252255
result = CALLBACK.newSuccessResult();
253-
result.put("invoke", getInvokeResult(clazz, instance, methodName, getArgList(req, "methodArgs")));
256+
result.put("invoke", ir == null ? null : ir.get("invoke"));
257+
result.put("types", ir == null ? null : ir.get("types"));
258+
result.put("args", ir == null ? null : ir.get("args"));
254259
result.put("instance", instance);
255260
}
256261
catch (Exception e) {
@@ -413,7 +418,7 @@ public static Method getInvokeMethod(Class<?> clazz, String methodName, List<Arg
413418
* @return
414419
* @throws Exception
415420
*/
416-
public static Object getInvokeResult(Class<?> clazz, Object instance, String methodName, List<Argument> methodArgs) throws Exception {
421+
public static JSONObject getInvokeResult(Class<?> clazz, Object instance, String methodName, List<Argument> methodArgs) throws Exception {
417422
Objects.requireNonNull(clazz);
418423
Objects.requireNonNull(methodName);
419424

@@ -427,8 +432,11 @@ public static Object getInvokeResult(Class<?> clazz, Object instance, String met
427432
initTypesAndValues(methodArgs, types, args, true);
428433
}
429434

430-
//TODO method 也缓存起来
431-
return clazz.getMethod(methodName, types).invoke(instance, args);
435+
JSONObject result = new JSONObject();
436+
result.put("invoke", clazz.getMethod(methodName, types).invoke(instance, args));
437+
result.put("types", types);
438+
result.put("args", args);
439+
return result;
432440
}
433441

434442

0 commit comments

Comments
 (0)