Nemo

Nemo 关注TA

路漫漫其修远兮,吾将上下而求索。

Nemo

Nemo

关注TA

路漫漫其修远兮,吾将上下而求索。

  •  普罗旺斯
  • 负责帅就完事了
  • 写了1,493,291字

该文章投稿至Nemo社区   Java  板块 复制链接


JoinPoint获取访问的类名前/方法前的注解

发布于 2017/04/24 18:47 10,594浏览 1回复 1,230



/**
* 访问拦截
* @author:Nemo 20170424
*/
@Aspect
@Component
public class AuthAop {

private final Logger logger = Logger.getLogger(getClass());

/**
* 定义切点,所有的controller下的访问都拦截
*/
@Pointcut("execution( * com.nemo.backend.controller..*(..))")
public void pointCutAt() {}

@Before("pointCutAt()")
public void beforeAction(JoinPoint point) throws OmegaException, NoSuchMethodException {

Class cls = point.getSignature().getDeclaringType();
boolean isNoCheckAuth = cls.isAnnotationPresent(NoCheckAuth.class);
if(isNoCheckAuth){
//类名前注解
Annotation noCheckAuth = cls.getAnnotation(NoCheckAuth.class);
}

//拦截的方法名称
String methodName = point.getSignature().getName();
//拦截的放参数类型
Class[] parameterTypes = ((MethodSignature)point.getSignature()).getMethod().getParameterTypes();
Method method = point.getSignature().getDeclaringType().getMethod(methodName,parameterTypes);
isNoCheckAuth = method.isAnnotationPresent(NoCheckAuth.class);

//如果方法前注解为不拦截登录
if(isNoCheckAuth){
//方法前的注释
NoCheckAuth noCheckAuth = method.getAnnotation(NoCheckAuth.class);
}

}

}
点赞(0)
点了个评