其他分享
首页 > 其他分享> > 注解的使用

注解的使用

作者:互联网

1.获取特定注解ExcelProperty的字段

    //存放注解作用的字段属性
    List<String> annotationValueList = new ArrayList<>();
    //存放实体对应所有注解
    List<Annotation> annotationList = new ArrayList<>();

    Field[] fields = ParamImportEntity.class.getDeclaredFields();
    for (Field field : fields) {
        Annotation[] annotations = field.getAnnotations();
        List<Annotation> asList = Arrays.asList(annotations);
        annotationList.addAll(asList);
    }
    for (Annotation annotation : annotationList) {
        if (annotation instanceof ExcelProperty) {
            String[] value = ((ExcelProperty) annotation).value();
            List<String> strings = Arrays.asList(value);
            annotationValueList.addAll(strings);
        }
    }

标签:ExcelProperty,List,annotationList,使用,注解,annotation,asList
来源: https://www.cnblogs.com/fightmonster/p/15864590.html