struts2封装数据过程

1、不实现modelDriven接口,那么params拦截器会通过ognl去取栈顶的对象,然后进行封装。

2、实现了modelDriven接口.

public String intercept(ActionInvocation invocation) throws Exception {
        Object action = invocation.getAction();

        if (action instanceof ModelDriven) {
            ModelDriven modelDriven = (ModelDriven) action;
            ValueStack stack = invocation.getStack();
            //取出model
            Object model = modelDriven.getModel();
            if (model !=  null) {
                //压入栈顶
            	stack.push(model);
            }
            if (refreshModelBeforeResult) {
                invocation.addPreResultListener(new RefreshModelBeforeResult(modelDriven, model));
            }
        }
        return invocation.invoke();
    }

从源码可以看出实现了modelDriven接口,那么直接压入栈顶.params拦截去去栈顶获取对象,封装到model中。

相关推荐