use of com.blade.mvc.view.ModelAndView in project blade by biezhi.
the class RouteViewResolve method handle.
public void handle(Request request, Response response, Route route) throws Exception {
try {
Method actionMethod = route.getAction();
Object target = route.getTarget();
int len = actionMethod.getParameterTypes().length;
Object returnParam;
if (len > 0) {
Object[] args = MethodArgument.getArgs(request, response, actionMethod);
returnParam = ReflectKit.invokeMehod(target, actionMethod, args);
} else {
returnParam = ReflectKit.invokeMehod(target, actionMethod);
}
if (null != returnParam) {
Class<?> returnType = returnParam.getClass();
RestController restController = target.getClass().getAnnotation(RestController.class);
JSON json = actionMethod.getAnnotation(JSON.class);
if (null != restController || null != json) {
response.json(viewSettings.toJSONString(returnParam));
} else {
if (returnType == String.class) {
response.render(returnParam.toString());
} else if (returnType == ModelAndView.class) {
ModelAndView modelAndView = (ModelAndView) returnParam;
response.render(modelAndView);
}
}
}
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
throw new BladeException(e.getCause());
} catch (Exception e) {
throw e;
}
}
Aggregations