使用Nutz的Mirror.me获取所有字段,然后字段上有一个自定义注解,但是通过field.isAnnotationPresend()方法判断为false
代码实例如下:
public @interface IsTemplate {
}
@Table("ad_account")
public class AccountModel extends BaseModel {
@Name
@IsTemplate
private String passport;
@Column
@Default("0")
@IsTemplate
private int noAuth;
@Column
private String city;
public String getPassport() {
return passport;
}
public void setPassport(String passport) {
this.passport = passport;
}
public int getNoAuth() {
return noAuth;
}
public void setNoAuth(int noAuth) {
this.noAuth = noAuth;
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
public static void main(String[] args) {
for (Field field : Mirror.me(AccountModel.class).getFields()) {
System.out.println(field.getName() + field.isAnnotationPresent(Column.class)); // 可以正确判断Column的注解字段
System.out.println(field.getName() + field.isAnnotationPresent(IsTemplate.class)); // 这里判断自定义注解,始终是false
}
}
}