-
简单注解类
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
相关推荐
全栈老实人_32 分钟前
考研互学互助系统|Java|SSM|VUE| 前后端分离天天进步201536 分钟前
Java全栈项目实战:校园报修服务系统Themberfue1 小时前
Java 网络原理 ①-IO多路复用 || 自定义协议 || XML || JSONwm10431 小时前
JavaEE 3大组件 Listener Servlet Filter疯一样的码农2 小时前
基于Spring Boot + Vue3实现的在线商品竞拍管理系统源码+文档m0_748251353 小时前
【SpringBoot】日志文件m0_748234713 小时前
Java-33 深入浅出 Spring - FactoryBean 和 BeanFactory BeanPostProcessor知初~3 小时前
java相关学习文档或网站整理码农小灰3 小时前
什么是缓存穿透、缓存击穿、缓存雪崩,在项目中是如何解决和预防?它们分别会带来什么危害?a栋栋栋3 小时前
apifox