2015-09-04 133 views
0

我有一个@Before方法,它返回一些我希望在切入点内使用的标记。AspectJ是否有一种方法可以从Before获取返回值并在切入点内使用它?

@Pointcut("execution(getData())") 
    private void selectAll(){} 

@Before("selectAll()") 
public void beforeAdvice(ProceedingJoinPoint joinPoint) throws Throwable{ 
    //Return the token 
} 
public void getData(){ 
    //Is there a way I can use the token returned by before?? 
} 
@After("selectAll()") 
public void afterAdvice(ProceedingJoinPoint joinPoint) throws Throwable{ 
    //destroy the token 
} 

有没有一种方法可以使用getData()之前返回的标记?

回答

1

不,你不能,因为你想做的事没有任何逻辑意义是什么:顾名思义

  • ,则@Before建议运行之前执行目标方法
  • 但是在执行方法之前,只有在执行之后才能有返回值。
  • 因此,您只能在@After@Around建议中处理返回值,在后一种情况下,您可以通过proceed()得到结果。
  • 您的代码意味着您要“使用之前返回的令牌”。但@Before建议有一个void返回类型,即它不返回任何内容。那么你想用什么?

请让我知道你是否需要一些示例代码。

相关问题