forked from AndrewProgramming/JavaTutorialCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTest08.java
More file actions
30 lines (21 loc) · 838 Bytes
/
Test08.java
File metadata and controls
30 lines (21 loc) · 838 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package reflection;
import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
public class Test08 {
public static void main(String[] args) throws NoSuchFieldException {
Class c1 = MyStudent.class;
Annotation[] annotations = c1.getAnnotations();
for (Annotation item : annotations) {
System.out.println(item);
}
TableStudent tableStudent = (TableStudent) c1.getAnnotation(TableStudent.class);
String value = tableStudent.value();
System.out.println(value);
Field field = c1.getDeclaredField("id");
FiledStudent annotation = field.getAnnotation(FiledStudent.class);
System.out.println(annotation.columnName());
System.out.println(annotation.type());
System.out.println(annotation.length());
//在数据库里根据注解的值创建对应的表结构
}
}