开发者社区> 问答> 正文

JAVA如何获得被注解的成员变量

下面是我自定义的注解:
screenshot
我在哪个成员变量是使用这个注解,就表示哪个成员变量是一个“索引”:

public class User {
    @Index
    private String scenicId;
    private String pinyin;
    private String title;
    private String cityName; // 城市名字
    private String cityCode;
    private String stateCode;
    private String stateName;
    private String continentCode;
    private String continentName;
    private String countryCode;
    private String countryName;
    private double latitude;
    private double longitude;
    private String geohash;// 景点的GEOHASH编码
    private String location;// 位置
    private String image; // 这个景点所对应的一张照片。相当于封面
    private double  score; // 此score是此地点的平均分
    private List<String> themes; // 此地点最受欢迎的几个主题
    private int commentCount = 0;// 评论数
    private int collectCount = 0; // 收藏数
    private String visitorUpdateInfo; // 用户贡献的信息,一次只能有一个
    private int scoreCount = 0; // 打分的人数
    private long createTime; // 创建时间
    private String type;
    private String introduction; // 描述(几个字描述)
    private String descriptions; // 概述
    private int titleSize;// 记录了标题的长度,可以用来做搜索。按照标题长度来匹配
    getter and setter···
}

在scenicId上面使用注解,就表示scenicId是需要建立索引的。但是我使用如下的方法,没有得到任何索引值:

User  user=new User();
   Annotation[] annotations = user.getClass().getAnnotations();
   System.out.println(annotations.length);
   for (Annotation annotation : annotations) {
   }

请问我该如何获得被注解的成员变量(在这里就是“scenicId”)?

展开
收起
蛮大人123 2016-02-22 16:57:11 3666 0
1 条回答
写回答
取消 提交回答
  • 我说我不帅他们就打我,还说我虚伪

    screenshot

    2019-07-17 18:46:53
    赞同 展开评论 打赏
问答分类:
问答标签:
问答地址:
问答排行榜
最热
最新

相关电子书

更多
Spring Cloud Alibaba - 重新定义 Java Cloud-Native 立即下载
The Reactive Cloud Native Arch 立即下载
JAVA开发手册1.5.0 立即下载