@Before(value = "@annotation(OwnershipCheck) && args(enquiry)")
public void checkOwnership(Enquiry enquiry) throws Throwable
{
}
以上表达式将匹配任何带有 OwnershipCheck 注释的方法,并将查询作为参数。
如何使用 OwnershipCheck 注释为任何方法扩展此表达式,并在有或没有其他参数的情况下在任何位置进行查询。
也就是需要匹配
@OwnershipCheck
public void one(Enquiry enquiry)
@OwnershipCheck
public void two(Object obj, Enquiry enquiry)
@OwnershipCheck
public void three(Enquiry enquiry, Object ob)
@OwnershipCheck
public void four(Object obj, Enquiry enquiry, Object other)
最佳答案
这是我的做法:
@Pointcut("@annotation(protections) && args(request,..)")
private void httpRequestAsFirstParam(Protections protections, HttpServletRequest request){}
@Pointcut("@annotation(protections) && args(..,request)")
private void httpRequestAsLastParam(Protections protections, HttpServletRequest request){}
@Pointcut("@annotation(protections) && args(*,request,..)")
private void httpRequestAsSecondParam(Protections protections, HttpServletRequest request){}
@Around("httpRequestAsFirstParam(protections, request) " +
"|| httpRequestAsLastParam(protections, request) " +
"|| httpRequestAsSecondParam(protections, request)")
public Object protect(ProceedingJoinPoint joinPoint, Protections protections, HttpServletRequest request) throws Throwable {
//...
}
您不能执行 args(.., enquiry, ..)
,但可以使用 args(*, enquiry, ..)
并结合第一个和最后一个参数匹配器。
关于java - 任意位置参数的切入点表达式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5568617/