【发布时间】:2020-12-23 06:09:38
【问题描述】:
这是注释代码:
@Target({ElementType.METHOD, ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Inherited
@Documented
public @interface PreVisit {
String value();
}
这个在Controller中使用@PreVisit("@pv.hasAccess('xxxxxx')")
@PreVisit("@pv.hasAccess('xxxxxx')")
@RequestMapping(value = "getUser")
public User getUser(Integer userId) {...some code...}
这是 pv.hasAccess('xxxxxx') 代码:
@Service("pv")
public class PageVisit{
public boolean hasAccess(String par){
//return false or true;
}
}
我的问题:
在Aspect中,如何获取注解参数中的方法并获取执行结果
这是Aspect文件代码:
@Aspect
@Component
public class PreVisitAspect {
@Around("@annotation(PreVisit)")
public Object around(ProceedingJoinPoint joinPoint) throws Throwable {
//How do I get the result of the method execution in the annotation parameter here
//boolean pvResult=@pv.hasAccess('xxxxxx'); pvResult=false or true
//Do something use the pvResult
}
}
【问题讨论】:
标签: java annotations aspect