diff --git a/springbootpt9c5/src/main/java/com/annotation/APPLoginUser.java b/springbootpt9c5/src/main/java/com/annotation/APPLoginUser.java index 124e996e..1ec5671b 100644 --- a/springbootpt9c5/src/main/java/com/annotation/APPLoginUser.java +++ b/springbootpt9c5/src/main/java/com/annotation/APPLoginUser.java @@ -4,9 +4,12 @@ import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; -//11111 -@Target(ElementType.PARAMETER) -@Retention(RetentionPolicy.RUNTIME) -public @interface APPLoginUser { +/** + * 自定义注解:APPLoginUser + * 用于标记方法参数,表示该参数需要从上下文中获取登录用户信息。 + */ +@Target(ElementType.PARAMETER) // 表明该注解只能用于方法参数上 +@Retention(RetentionPolicy.RUNTIME) // 注解在运行时可用,可以通过反射获取 +public @interface APPLoginUser { } diff --git a/springbootpt9c5/src/main/java/com/annotation/IgnoreAuth.java b/springbootpt9c5/src/main/java/com/annotation/IgnoreAuth.java index d92a9ef8..dd14abce 100644 --- a/springbootpt9c5/src/main/java/com/annotation/IgnoreAuth.java +++ b/springbootpt9c5/src/main/java/com/annotation/IgnoreAuth.java @@ -2,9 +2,19 @@ package com.annotation; import java.lang.annotation.*; +// 定义一个自定义注解名为 IgnoreAuth +// 使用 @Target 注解指定该注解可以应用的目标元素类型为方法(ElementType.METHOD) @Target(ElementType.METHOD) + +// 使用 @Retention 注解指定该注解在运行时是否可用 +// RetentionPolicy.RUNTIME 表示该注解在运行时可以通过反射获取 @Retention(RetentionPolicy.RUNTIME) + +// 使用 @Documented 注解表示该注解会被包含在 JavaDoc 文档中 @Documented + +// 定义一个空的自定义注解 IgnoreAuth public @interface IgnoreAuth { } + diff --git a/springbootpt9c5/src/main/java/com/annotation/LoginUser.java b/springbootpt9c5/src/main/java/com/annotation/LoginUser.java index eb7cacf6..1d0208fd 100644 --- a/springbootpt9c5/src/main/java/com/annotation/LoginUser.java +++ b/springbootpt9c5/src/main/java/com/annotation/LoginUser.java @@ -4,8 +4,16 @@ import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; +// 定义一个自定义注解名为 LoginUser +// 使用 @Target 注解指定该注解可以应用的目标元素类型为参数(ElementType.PARAMETER) @Target(ElementType.PARAMETER) + +// 使用 @Retention 注解指定该注解在运行时是否可用 +// RetentionPolicy.RUNTIME 表示该注解在运行时可以通过反射获取 @Retention(RetentionPolicy.RUNTIME) + +// 定义一个空的自定义注解 LoginUser public @interface LoginUser { } +