@AnnotationField(tableName = "tb_animal", flag = 0)//使用多個注解值,中間用,割開,如果不想使用默認值,可以在注解中為其重新賦值 @AnnotationTest1("tb_animal") public class Animal { private String name; private String sex; private Integer age; }
比如獲取Animal這個類上的注解:
public static void main(String[] args) throws Exception{ Class<?> animal = Class.forName("annotation.Animal"); AnnotationField annotationField = animal.getAnnotation(AnnotationField.class); if (annotationField!=null){ //annotationField : @annotation.AnnotationField(flag=0, tableName=tb_animal) System.out.println("annotationField : "+annotationField); //0 tb_animal interface annotation.AnnotationField System.out.println(annotationField.flag()+" "+annotationField.tableName()+" "+annotationField.annotationType()); } }