doc

介绍

封装了注解获取等方法的工具类。

使用

方法介绍

  1. 注解获取相关方法:

例子:

我们定义一个注解:

// Retention注解决定MyAnnotation注解的生命周期
@Retention(RetentionPolicy.RUNTIME)
// Target注解决定MyAnnotation注解可以加在哪些成分上,如加在类身上,或者属性身上,或者方法身上等成分
@Target({ ElementType.METHOD, ElementType.TYPE })
public @interface AnnotationForTest {
	
	/**
	 * 注解的默认属性值
	 * 
	 * @return 属性值
	 */
	String value();
}

给需要的类加上注解:

@AnnotationForTest("测试")
public static class ClassWithAnnotation{

}

获取注解中的值:

// value为"测试"
Object value = AnnotationUtil.getAnnotationValue(ClassWithAnnotation.class, AnnotationForTest.class);
  1. 注解属性获取相关方法:

更多方法见API文档:

https://apidoc.gitee.com/loolly/hutool/cn/hutool/core/annotation/AnnotationUtil.html