只是小知识点,有点意思,记下来
因为 可以简化成下面两段代码:
before(invocation);
// 调用下一个拦截器,如果拦截器不存在,则执行Action
result = invocation.invoke();
after(invocation, result);
----------------------------------
interceptor.getInterceptor().intercept(DefaultActionInvocation.this);
----------------------------------
相当于递归前后加执行语句,相当于一层层的执行,加上很多的分支,类似下面的结构
所以before是从外到内,after是从内到外,一一对应
before();
{
before();
{
before();
{
before();
{
//invocation.invoke();
}
after();
}
after();
}
after();
}
after();
利用到了递归中增加层次,从而实现堆+栈效果,有点类似多层ifelse