我可以做
@Pointcut("@annotation(com.learning.validation.Validate)")
public void validatePointCut() {
}
@AfterReturning(pointcut = "validatePointCut()")
public void validate(JoinPoint joinPoint) {
// some code
}
但我做不到
@Pointcut("@annotation(com.learning.validation.Validate)")
public void validatePointCut() {
}
@Before(pointcut = "validatePointCut()")
public void validate(JoinPoint joinPoint) {
// some code
}
我必须做
@Before("@annotation(com.learning.validation.Validate)")
public void validate(JoinPoint joinPoint) {
// some code
}
我希望使用@Before 与@AfterReturning 相同, 我正在使用 Spring Boot 3.x 和 Spring AOP 我是否遗漏了什么,或者它应该如何工作
@Before
只知道切入点表达式的默认参数名称value
,而@AfterReturning
为其定义了一个额外的别名pointcut
。
即,对于
@Before
,您可以写任何
@Before("validatePointCut()")
,@Before(value = "validatePointCut()")
,而对于
@AfterReturning
你可以写任何
@AfterReturning("validatePointCut()")
,@AfterReturning(value = "validatePointCut()")
,@AfterReturning(pointcut = "validatePointCut()")
.我建议您学习如何使用 IDE 的功能,以便在输入程序时能够直接从代码编辑器中找到您使用的 API。