action实现modelDriven接口的运行流程(源码解析)

核心源码


public class ModelDrivenInterceptor extends AbstractInterceptor {
 
	@Override
    	public String intercept(ActionInvocation invocation) throws Exception {
            // 步骤2
        	Object action = invocation.getAction();
		   // 步骤3
	        if (action instanceof ModelDriven) {
			    
           	 	ModelDriven modelDriven = (ModelDriven) action;
			
            		ValueStack stack = invocation.getStack();
			
            		Object model = modelDriven.getModel();
            		if (model !=  null) {
			
            			stack.push(model);
            		}
        	}
        	return invocation.invoke();
    	}
}

1.先会执行ModelDrivenInterceptor的intercept方法

2.获取action对象

3.判断Action类是否实现modelDriven接口,如果实现即强转。调用modelDriven的getModel方法,实际上是Action的getModel方法。将action内的成员变量放入值栈栈顶。

4.再执行ParametersInterceptor的intercept方法:把请求参数的值赋给栈顶对象对应的属性。若栈顶对象没有对应的属性,则查询值栈中下一个对象对应的属性

猜你喜欢

转载自blog.csdn.net/qq_41175067/article/details/82115263