自定义注解初始--切面log记录交互日志

一、 自定义 注解 的 参数

​
/**
 * 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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值