-
简单注解类
java@Target({ElementType.METHOD, ElementType.ANNOTATION_TYPE}) @Retention(RetentionPolicy.RUNTIME) @Documented public @interface ErasePasswordAnno { @AliasFor(attribute = "expression") String value() default "" ; String expression() default "" ; }
-
嵌套注解类
java@Target({ElementType.METHOD}) @Retention(RetentionPolicy.RUNTIME) @Documented @ErasePasswordAnno public @interface MapErasePasswordAnno { @AliasFor(annotation = ErasePasswordAnno.class, attribute = "value") String value() default "['recordList']" ; @AliasFor(annotation = ErasePasswordAnno.class, attribute = "expression") String expression() default "['recordList']" ; }
-
编写测试代码
java@Slf4j public class AliasForAnnoTest { @Test void simple() throws NoSuchMethodException { Method method = MapErasePasswordAnnoTest.class.getMethod("hello"); ErasePasswordAnno annotation = AnnotationUtils.getAnnotation(method, ErasePasswordAnno.class); Assertions.assertNotNull(annotation); log.info("annotation value : {}", annotation.value()); log.info("annotation expression : {}", annotation.value()); } @Test void complex() throws NoSuchMethodException { Method method = MapErasePasswordAnnoTest.class.getMethod("hello2"); ErasePasswordAnno annotation = AnnotatedElementUtils.findMergedAnnotation(method, ErasePasswordAnno.class); Assertions.assertNotNull(annotation); log.info("annotation value : {}", annotation.value()); log.info("annotation expression : {}", annotation.value()); } @ErasePasswordAnno("username") public void hello(){ } @MapErasePasswordAnno public void hello2(){ } }
注解Spring @AliasFor使用笔记
yicj2024-08-06 14:25
相关推荐
九术沫1 天前
装饰器模式在Spring中的案例Rysxt_1 天前
Spring Boot 集成 Spring AI OpenAI Starter 教程青云交1 天前
Java 大视界 -- Java 大数据在智能家居场景联动与用户行为模式挖掘中的应用AAA修煤气灶刘哥1 天前
ES 高级玩法大揭秘:从算分骚操作到深度分页踩坑,后端 er 速进!江团1io01 天前
深入解析MVCC:多版本并发控制的原理与实现树码小子1 天前
Java网络编程:(socket API编程:UDP协议的 socket API -- 回显程序的服务器端程序的编写)君宝1 天前
Linux ALSA架构:PCM_OPEN流程 (二)云深麋鹿1 天前
数据链路层总结fire-flyer1 天前
响应式客户端 WebClient详解北执南念1 天前
基于 Spring 的策略模式框架,用于根据不同的类的标识获取对应的处理器实例