3.再定义一个Page注解:
  package com.test.annotation;
  import java.lang.annotation.ElementType;
  import java.lang.annotation.Retention;
  import java.lang.annotation.RetentionPolicy;
  import java.lang.annotation.Target;
  @Target(ElementType.FIELD)
  @Retention(RetentionPolicy.RUNTIME)
  public @interface Page {
  public String name() default "";
  }
  4.同样的,需要实现下Page注解
package com.test.annotation;
import java.lang.reflect.Field;
import java.util.Iterator;
public class AutoPage {
public void setPageAnnotation(){
Iterator<String> it = InitialManger.allInstance.keySet().iterator();
while(it.hasNext()){
String key = it.next();
try {
Class<?> c = InitialManger.allInstance.get(key).getClass();
Field[] fields = c.getDeclaredFields();
for (Field field : fields) {
field.setAccessible(true);
if(field.isAnnotationPresent(Page.class)){
field.set(InitialManger.allInstance.get(key), InitialManger.allInstance.get(field.getAnnotation(Page.class).name()));
}
}
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (SecurityException e) {
e.printStackTrace();
} catch (IllegalArgumentException e) {
e.printStackTrace();
}
}
}
public void setTestAnnotation(Object o) {
try {
Class<?> c = o.getClass();
Field[] fields = c.getDeclaredFields();
for (Field field : fields) {
field.setAccessible(true);
if(field.isAnnotationPresent(Page.class)){
field.set(o, InitialManger.allInstance.get(field.getAnnotation(Page.class).name()));
}
}
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (SecurityException e) {
e.printStackTrace();
} catch (IllegalArgumentException e) {
e.printStackTrace();
}
}
}
  5.增加一个所有page实例化后的对象管理类:
  package com.test.annotation;
  import java.util.HashMap;
  import java.util.Map;
  public class InitialManger {
  public static Map<String, Object> allInstance = new HashMap<String, Object>();
  }