????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>();
????}