# 自訂義 Annotation ###### tags: `Spring` `Annotation` ### 標籤 1. [@Target](https://docs.oracle.com/javase/7/docs/api/java/lang/annotation/Target.html):限定 Annotation 使用對象 | | 使用對象 | | --- | -------- | TYPE | 適用 class, interface, enum | | FIELD | 適用 field | | ANNOTATION_TYPE | 適用 Annotation 型態 | 2. [@Retention](https://docs.oracle.com/javase/7/docs/api/java/lang/annotation/Retention.html):告知編譯器如何處理 Annotation | | CLASS | JVM | 說明 | | ------- | ----- | ------ | --- | | CLASS | 保留 | 不保留 | 預設 | | RUNTIME | 保留 | 保留 | | | SOURCE | 拋棄 | 拋棄 | 編譯後直接拋棄 | 3. [@Constraint](https://docs.oracle.com/javaee/7/api/javax/validation/Constraint.html):決定對象可以使用 @Valid 驗證 * validatedBy:指定 Validator (驗證器)的 class 4. [@Documented](https://docs.oracle.com/javase/7/docs/api/java/lang/annotation/Documented.html):表明這個 Annotation 可以被 Java Doc 紀錄 5. 實作密碼與再輸入密碼判別是否相同的 Annotation > https://www.baeldung.com/java-custom-annotation