Java 如何迭代bean/Object中的所有属性/字段,包括引用对象/bean
[背景]Java 如何迭代bean/Object中的所有属性/字段,包括引用对象/bean,java,spring,apache,reflection,Java,Spring,Apache,Reflection,[背景] 公共类所有{ 私有列表列表c; 私人b类; @自定义符号 私有字符串all1; } 公共B级{ @自定义符号 字符串A; B串; @自定义符号 C类 ... } 公共C类{ @自定义符号 字符串d; 字符串e; } 公共列表myProcess(所有bean)抛出BusinessException; 问题: 如何获取由@customerNotation标记的所有字段,包括引用对象字段 [field.getAnnotation(customerAnnotation.class)],它只能
公共类所有{
私有列表列表c;
私人b类;
@自定义符号
私有字符串all1;
}
公共B级{
@自定义符号
字符串A;
B串;
@自定义符号
C类
...
}
公共C类{
@自定义符号
字符串d;
字符串e;
}
公共列表myProcess(所有bean)抛出BusinessException;
问题:
@customerNotation
标记的所有字段,包括引用对象字段[field.getAnnotation(customerAnnotation.class)]
,它只能获得第一名,但我想获得第二名、第三名你能试试这个吗
Class aClass = All.class;
Annotation[] annotations = aClass.getAnnotations();
for(Annotation annotation : annotations){
if(annotation instanceof MyAnnotation){
MyAnnotation myAnnotation = (MyAnnotation) annotation;
System.out.println("name: " + myAnnotation.name());
}
}