spring aop中引介拦截器的用法

public class Other implements IntroductionInterceptor,IOther{
 public void doOther(){
  System.out.println("Other对象的功能");
 }
 
 public Object invoke(MethodInvocation methodInvocation) throws Throwable {
  if(implementsInterface(methodInvocation.getMethod().getDeclaringClass())){
   return methodInvocation.getMethod().invoke(this, methodInvocation.getArguments());
  }
  else{
   return methodInvocation.proceed();
  }
 }
 public boolean implementsInterface(Class arg0){
  boolean assignableFrom = arg0.isAssignableFrom(IOther.class);
  return assignableFrom;
 } 
}

 

posted @ 2020-01-10 21:45  ppjj  阅读(523)  评论(0编辑  收藏  举报