一、 自定义 注解 的 参数
/**
* AroundLog注解
*
* @author 华中强
* @date 2024-09-20
*/
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.METHOD})
@Documented
public @interface AuditLog {
/**
* 操作描述
* @return
*/
String opBusinessName() default "";
/**
* 操作类型(增删改查)
* @return
*/
OperateEnum type() default OperateEnum.MODIFY;
/**
* 业务唯一标识,如订单id
* @return
*/
String opBusinessId() default "";
/**
* @author: Huazq
* @description: 成功字段
* @date: 2025/2/10 13:42
* @Params
*/
String successField() default "";
/**
* @author: Huazq
* @description: 成功值
* @date: 2025/2/10 13:42
* @Params
*/
String successValue() default "";
}
2 翻看源码得出 @Retention(RetentionPolicy.RUNTIME) 是控制注解什么时候执行,
/*
* Copyright (c) 2003, 2004, Oracle and/or its affiliates. All rights reserved.
* ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
*
*/
package java.lang.annotation;
/**
* Annotation retention policy. The constants of this enumerated type
* describe the various policies for retaining annotations. They are used
* in conjunction with the {@link Retention} meta-annotation type to specify
* how long annotations are to be retained.
*
* @author Joshua Bloch
* @since 1.5
*/
public enum RetentionPolicy {
/**
* Annotations are to be discarded by the compiler.
*/
SOURCE,
/**
* Annotations are to be recorded in the class file by the compiler
* but need not be retained by the VM at run time. This is the default
* behavior.
*/
CLASS,
/**
* Annotations are to be recorded in the class file by the compiler and
* retained by the VM at run time, so they may be read reflectively.
*
* @see java.lang.reflect.AnnotatedElement
*/
RUNTIME
}
2 翻看源码得出
@Target(ElementType.METHOD)
: 这个元注解表示AuditLog
注解只能用于方法上。
/*
* Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
* ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
*
*/
package java.lang.annotation;
/**
* The constants of this enumerated type provide a simple classificatio