如题,我自定义了一个注解类 @ AuditAttribute
我在java实体类的get方法上面加上这个注解,然后用
Annotation annotation = f.getAnnotation(AuditAttribute.class);
Annotation[] methodAnnotations = method.getAnnotations();
这样来取,不管是取多个还是取一个,取到的总是null 这是为什么?
如题,我自定义了一个注解类 @ AuditAttribute
我在java实体类的get方法上面加上这个注解,然后用
Annotation annotation = f.getAnnotation(AuditAttribute.class);
Annotation[] methodAnnotations = method.getAnnotations();
这样来取,不管是取多个还是取一个,取到的总是null 这是为什么?
这个是我写的你看看
public class Person {
private String id ;
@Scope("prototype")
public String getId(){
return id ;
}
}
public static void test(Object obj){
Method[] method = obj.getClass().getDeclaredMethods();// 获取所有方法
for (java.lang.reflect.Method m : method) {
System.out.println(m.getName());
if (m.getName().startsWith("get")) {// 取方法名为get...的
if(null != m.getDeclaredAnnotations()){
System.out.println("--111--"+m.getName());
Annotation[] ano = m.getDeclaredAnnotations();
System.out.println("--222--"+ano[0]);
}
public static void main(String[] args) throws NoSuchMethodException, SecurityException{
test(new Person());
}
-------------------------打印结果
getId
--111--getId
--222--@org.springframework.context.annotation.Scope(proxyMode=DEFAULT, value=prototype)