⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 otherintroduction.java

📁 spring2.0技术手册随书事例,结合例子学习起来更轻松
💻 JAVA
字号:
package onlyfun.caterpillar;

import org.aopalliance.intercept.MethodInvocation;
import org.springframework.aop.IntroductionInterceptor;

public class OtherIntroduction 
              implements IntroductionInterceptor, IOther {   
    //是否实现自IOther接口
    public boolean implementsInterface(Class clazz) {
        return clazz.isAssignableFrom(IOther.class);
    }
    
    public Object invoke(MethodInvocation methodInvocation) 
                                      throws Throwable {
        //如果调用的方法来自IOther接口的定义
        if(implementsInterface(
            methodInvocation.getMethod().getDeclaringClass())) {
            //调用额外加入(mixin)的行为
            return methodInvocation.getMethod().
                    invoke(this, methodInvocation.getArguments());
        }
        else {
            return methodInvocation.proceed();
        }
    }
    
    public void doOther() {
        System.out.println("增加的职责...");
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -