自定义注解
@Target({ ElementType.METHOD, ElementType.TYPE })
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface OperateLog{
String value();
}
添加切面监听
@Aspect
@Component
public class OperateAspect {
@Pointcut("@annotation(com.XXX.OperateLog)")
public void annotationPointCut() {
}
@Before("annotationPointCut()")
public void before(JoinPoint joinPoint){
MethodSignature sign = (MethodSignature)joinPoint.getSignature();
Method method = sign.getMethod();
OperateLog annotation = method.getAnnotation(OperateLog.class);
System.out.print("打印:"+annotation.value()+" 前置日志");
}
}
引用
@OperateLog("测试")