在spring的aop中获取自定义注解的参数值,即在切面中获取annotation的参数值

annotation

@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface Delete {

	String key() default "";
}

切面(aspect)

@Aspect
@Component
public class Aspect {

	@After(value = "@annotation(d)", argNames = "d")
	public void after(Delete d) {
		System.out.println(d.key());
		System.out.println("after");
	}
}

使用

@Service
public class UserService {

	@Delete(key = "abc")
	public void update() {
		System.out.println("update user");
	}
}



版权声明:本文为zyf_balance原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。