|
|
@@ -16,9 +16,11 @@
|
|
|
|
|
|
package com.jfinal.core;
|
|
|
|
|
|
+import java.util.function.BiFunction;
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
import com.jfinal.config.Constants;
|
|
|
+import com.jfinal.core.paragetter.JsonRequest;
|
|
|
import com.jfinal.aop.Invocation;
|
|
|
import com.jfinal.handler.Handler;
|
|
|
import com.jfinal.kit.ReflectKit;
|
|
|
@@ -39,6 +41,21 @@ public class ActionHandler extends Handler {
|
|
|
protected static final RenderManager renderManager = RenderManager.me();
|
|
|
private static final Log log = Log.getLog(ActionHandler.class);
|
|
|
|
|
|
+ public static boolean resolveJson = false;
|
|
|
+
|
|
|
+ // 默认 JsonRequestFactory
|
|
|
+ private static BiFunction<String, HttpServletRequest, JsonRequest> jsonRequestFactory = (jsonString, req) -> {
|
|
|
+ return new JsonRequest(jsonString, req);
|
|
|
+ };
|
|
|
+
|
|
|
+ public static void setResolveJson(boolean resolveJson) {
|
|
|
+ ActionHandler.resolveJson = resolveJson;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void setJsonRequestFactory(BiFunction<String, HttpServletRequest, JsonRequest> jsonRequestFactory) {
|
|
|
+ ActionHandler.jsonRequestFactory = jsonRequestFactory;
|
|
|
+ }
|
|
|
+
|
|
|
protected void init(ActionMapping actionMapping, Constants constants) {
|
|
|
this.actionMapping = actionMapping;
|
|
|
this.devMode = constants.getDevMode();
|
|
|
@@ -83,6 +100,11 @@ public class ActionHandler extends Handler {
|
|
|
controller = controllerFactory.getController(action.getControllerClass());
|
|
|
controller._init_(action, request, response, urlPara[0]);
|
|
|
|
|
|
+ if (resolveJson && controller.isJsonRequest()) {
|
|
|
+ // 注入 JsonRequest 包装对象接管 request
|
|
|
+ controller.setHttpServletRequest(jsonRequestFactory.apply(controller.getRawData(), controller.getRequest()));
|
|
|
+ }
|
|
|
+
|
|
|
if (devMode) {
|
|
|
if (actionReporter.isReportAfterInvocation(request)) {
|
|
|
new Invocation(action, controller).invoke();
|