private Object injectParam2Pojo(Class<?> paramClass, String startName) throws Exception { Object paramObj = paramClass.newInstance(); ReflectUtil ru = new ReflectUtil(paramObj); this.injectActionCxt2Pojo(ru); // 注入mvc action 请求参数 ParamUtil.injectParam(this.context, ru, startName); return paramObj; }
private Object injectParam2Map(String startName) throws Exception { Map<String, Object> map = new HashMap<String, Object>(); ReflectUtil ru = new ReflectUtil(map); this.injectActionCxt2Pojo(ru); // 注入mvc action 请求参数 ParamUtil.injectParam(this.context, ru, startName); return map; }
/** * 执行Action * * @throws Exception */ public void execute() throws Exception { // 实例化pojo initPojo(); // IOC注入对象到pojo中 injectIocBean(); // 注入框架mvc action 上下文环境 this.injectActionCxt2Pojo(this.ru); if (IAction.class.isAssignableFrom(this.actionObject.getClass())) { // struts2风格 IAction action = (IAction) actionObject; action.init(this.context); retn = action.execute(); // 对Action执行返回结果的处理 this.handleResult(); return; } String methodName = this.context.getActionConfigBean().getMethod(); Method[] methods = ru.getMethods(methodName); if (methods == null || methods.length == 0) return; method = this.getFirstMethd(methods); if (method == null) return; // 执行验证器 this.handleValidator(); try { // upload validation this.validateUpload(); // 注入mvc action 请求参数 ParamUtil.injectParam(this.context, this.ru, null); /* 方法体内的前置拦截器执行 */ Before before = method.getAnnotation(Before.class); if (before != null) { InterExecution before_interExe = new InterExecution("before", context); before_interExe.execute(before.value()); if (before_interExe.getError() != null) { before_interExe.showErr(); return; } } // execute the action method excuteMethod(methodName); /* 方法体内的后置拦截器执行 */ After after = method.getAnnotation(After.class); if (after != null) { // 后置拦截器 InterExecution after_interExe = new InterExecution("after", context); after_interExe.execute(after.value()); if (after_interExe.getError() != null) { after_interExe.showErr(); return; } } /* 外部配置的后置拦截器后执行 */ InterExecution after_interExe = new InterExecution("after", this.context); // 7.后置拦截器 if (after_interExe.findAndExecuteInter()) { after_interExe.showErr(); return; } // 对Action执行返回结果的处理 this.handleResult(); } catch (Exception e) { throw e; } }