?? testmyannotation.java
字號:
/**
* Copyright (c)上海煙草(集團)公司與上??禃r信息系統有限公司。
*/
package com.test.annotation;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
public class TestMyAnnotation{
private static Log log = LogFactory.getLog(TestMyAnnotation.class);
public static void main(String[] args){
log.info("--Class Annotations--");
if(GetMyAnnotation.class.isAnnotationPresent(MyAnnotation.class)){
log.info("[GetMyAnnotation].annotation:");
MyAnnotation classAnnotation = GetMyAnnotation.class.getAnnotation(MyAnnotation.class);
//log.info("1111");
//log.info("annotation3 is null:" + classAnnotation);
printMyAnnotation3(classAnnotation);
}
log.info("--Fields Annotations--");
Field[] fields = GetMyAnnotation.class.getDeclaredFields();
for(Field field:fields){
if(field.isAnnotationPresent(MyAnnotation.class)){
log.info("[GetMyAnnotation." + field.getName()+ "].annotation:");
MyAnnotation fieldAnnotation = field.getAnnotation(MyAnnotation.class);
printMyAnnotation3(fieldAnnotation);
}
}
log.info("--Methods Annotations--");
Method[] methods = GetMyAnnotation.class.getDeclaredMethods();
for(Method method:methods){
log.info("[GetMyAnnotation." + method.getName()+ "].annotation:");
if(method.isAnnotationPresent(MyAnnotation.class)){
//log.info("1111");
MyAnnotation methodAnnotation = method.getAnnotation(MyAnnotation.class);
printMyAnnotation3(methodAnnotation);
}
}
}
private static void printMyAnnotation3(MyAnnotation annotation3){
//log.info("1111");
//log.info("annotation3 is null:" + annotation3);
if(annotation3 == null){
return;
}
log.info("{value=" + annotation3.value());
String multiValues = "";
for(String value:annotation3.multiValues()){
multiValues += "," + value;
}
log.info("multiValues=" + multiValues);
log.info("number=" + annotation3.number() + "}");
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -