annotation 自定义注解

本文介绍了一种使用Java注解和面向切面编程(AOP)来定义切入点的方法。通过自定义注解MyAnnotation和切面类AnnotationImplement,可以在运行时拦截被该注解标记的方法并执行特定操作。
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

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

String descraption() default "";

}


@Aspect
@Component
public class AnnotationImplement {

@Pointcut("@annotation(com.aop.MyAnnotation)")
public void annotation(){
//任何代码都不会执行
}

@Around("annotation()")
public void afterPoint(ProceedingJoinPoint point){

System.out.println(point.getTarget().getClass().getName());
Object[] obj = point.getArgs();
for (int i = 0; i < obj.length; i++) {
System.out.println(obj.toString());
}
}
}


参考:https://my.oschina.net/xwl1990/blog/509192
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值