⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 testmyannotation.java

📁 jboss4 + Mysql +ejb3.0 EJB3 简单例子
💻 JAVA
字号:
/**
 * Copyright (c)上海烟草(集团)公司与上海康时信息系统有限公司。
 */
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 + -