【发布时间】:2014-05-30 08:31:38
【问题描述】:
在我的应用程序中,我的方法的参数由一些注释注释。现在我想编写 Aspect,使用来自注释属性的信息对注释参数进行一些预处理。例如方法:
public void doStuff(Object arg1, @SomeAnnotation CustomObject arg1, Object arg2){...}
方面:
@Before(...)
public void doPreprocessing(SomeAnnotation annotation, CustomObject customObject){...}
@Before 应该写什么?
编辑:
感谢大家。有我的解决方案:
@Before("execution(public * *(.., @SomeAnnotation (*), ..))")
public void checkRequiredRequestBody(JoinPoint joinPoint) {
MethodSignature methodSig = (MethodSignature) joinPoint.getSignature();
Annotation[][] annotations = methodSig.getMethod().getParameterAnnotations();
Object[] args = joinPoint.getArgs();
for (int i = 0; i < args.length; i++) {
for (Annotation annotation : annotations[i]) {
if (SomeAnnotation.class.isInstance(annotation)) {
//... preprocessing
}
}
}
}
【问题讨论】: