|
@@ -0,0 +1,36 @@
|
|
|
+package com.sf.anno.my_mybatis;
|
|
|
+
|
|
|
+import com.sf.anno.my_mybatis.entity.Student;
|
|
|
+
|
|
|
+import java.lang.reflect.Field;
|
|
|
+
|
|
|
+public class Test {
|
|
|
+
|
|
|
+ public static void main(String[] args) {
|
|
|
+ // 获取student类对象
|
|
|
+ //public class Student {
|
|
|
+ Class<Student> studentClass = Student.class;
|
|
|
+ // 获取类上的table注解 得到的是一个Table对象
|
|
|
+ // @Table("student")
|
|
|
+ Table tableAnno = studentClass.getAnnotation(Table.class);
|
|
|
+ String value = tableAnno.value();
|
|
|
+ System.out.println(value);
|
|
|
+
|
|
|
+ // 获取类的所有属性 得到属性数组
|
|
|
+ Field[] fields = studentClass.getDeclaredFields();
|
|
|
+ // iter 增强for循环的快捷键
|
|
|
+ // id name
|
|
|
+ for (Field field : fields) {
|
|
|
+ // @Column(name = "id",type = "int")
|
|
|
+ // @Column(name = "name", type = "varchar(100)")
|
|
|
+ // 每一个部分 也是一个对象 是注解对应的对象
|
|
|
+ Column column = field.getAnnotation(Column.class);
|
|
|
+ String name = column.name();
|
|
|
+ String type = column.type();
|
|
|
+ System.out.println(name + "," + type);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 通过获取不同位置的注解 来进行区分 以此得到配置化的处理
|
|
|
+ // select id,name from student;
|
|
|
+ }
|
|
|
+}
|