自定义注解
@Retention()
@Target(allowedTargets = AnnotationTarget.FUNCTION)
public @interface CheckLogin{
}
CheckLoginAspect
@Pointcut("execution(@xxx.xxxx.CheckLogin * *(..))")
private void methodAnnotated(){
}
@Around("methodAnnotated()")
public void checkLogin(ProceedingJoinPoint joinPoint) throws Throwable {//一定要是public
Signature signature = joinPoint.getSignature();//方法签名
Method method = ( (MethodSignature)signature).getMethod();
//这个方法才是目标对象上有注解的方法
Method realMethod = joinPoint.getTarget().getClass().getDeclaredMethod(method.getName(), method.getParameterTypes());
CheckLogin checkLogin = realMethod.getAnnotation(CheckLogin.class);
//下面这句代码是获得那个自定义的注解的对象
CheckLogin authorizationNeed = (method.getAnnotation(CheckLogin.class));
Log.e("checkLogin",(checkLogin == null) + "");
Log.e("authorizationNeed",(authorizationNeed == null) + "");
//这里两种getAnnotation的方式都为null,请大神指教,百思不得其解
}
MainActivity
@CheckLogin()
private void test(){
Toast.makeText(this,"跳转成功",Toast.LENGTH_SHORT).show();
}
胖子玩AOP的时候,报:Cause: zip file is empty
baidu、google一晚,还是google靠谱,这里记录下。
public void checkLogin(ProceedingJoinPoint joinPoint),这里的一定要是public。如果是private就会报Cause: zip file is empty