通过反射获取类的注解信息
package com.seven.classTest;
import java.lang.annotation.*;
import java.lang.reflect.Field;
public class TestAnnotation {
public static void main(String[] args) throws Exception {
Class c1 = Person01.class;
Annotation declaredAnnotation = c1.getDeclaredAnnotation(TableAnnotation.class);
TableAnnotation tableAnnotation = (TableAnnotation) declaredAnnotation;
System.out.println(tableAnnotation.value());
Field name = c1.getDeclaredField("name");
FieldAnnotation declaredAnnotation1 = name.getDeclaredAnnotation(FieldAnnotation.class);
FieldAnnotation fieldAnnotation = declaredAnnotation1;
System.out.println(fieldAnnotation.fieldName());
System.out.println(fieldAnnotation.fieldType());
System.out.println(fieldAnnotation.length());
}
}
@TableAnnotation("db_person")
class Person01{
@FieldAnnotation(fieldName = "id",fieldType = "varchar",length = 10)
private int id;
@FieldAnnotation(fieldName = "name",fieldType = "varchar",length = 5)
private String name;
public Person01() {
}
public Person01(int id, String name) {
this.id = id;
this.name = name;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name