Spring 自定義注解 操作日志
1.自定義注解
-
package com.jay.demo3.aop1.myannotation;
-
-
import java.lang.annotation.Documented;
-
import java.lang.annotation.ElementType;
-
import java.lang.annotation.Retention;
-
import java.lang.annotation.RetentionPolicy;
-
import java.lang.annotation.Target;
// 業(yè)務(wù)注解分類 -- 定義: 運行期間 基于方法 的 注解
* 常用注解說明: 1:。RetentionPolicy (保留 策略) 是 一個 enum 類型, 有三個 值:
source: -- 這個 annotation 類型 的 信息 只會 保留 在 程序 源碼里, 源碼 如果 經(jīng)過 了 編譯 后 ,annotation 的 數(shù)據(jù) 就會 消失。并不會 保留 在 編譯后 的 。class 文件里。
class -- 這個 annotation 類型 的 信息 會 保留 在 程序 的 源碼中,同時也會 保留 在 編譯好 的 .class 文件中。 在執(zhí)行的時候,并不會把這一些 信息 加載到虛擬機 (JVM) 中去, 注意 一下, 當(dāng)你 沒有設(shè)定 一個 annotation 類型 的 Retention 時,系統(tǒng)默認值是 class。
Runtime -- 在 源碼, 編譯好的 .class 文件中 保留信息, 在 執(zhí)行 的時候 會 把 這一些 信息 加載到 JVM 中去。
2. ElementType @Target 中 的 ElementType 用來 指定 Annotation 類型 可以 用在哪些 元素上。
Type: -- 在 class Interface ,Enum, 和 annotation 類型上
Field -- 屬性上
Method -- 方法上
Paramter /pe'raemiter/ -- 參數(shù)上
Constructor -- 構(gòu)造函數(shù)上
Local_Variable -- 局部變量
Annotation_Type -- annotation 類型上
package -- 包 上
3. Documented -- 讓 這個 annotation 類型的 信息 能夠 顯示 在 api 說明 文檔上。如果 沒有 添加 的話, 使用 javadoc 生成 的 API 文件 找不到 這個 類型 生成 的 信息。

浙公網(wǎng)安備 33010602011771號