java - 如何使用注释正确地从 bean 中提取字段
问题描述
我有一个带有注释的 getter 和字段的 bean:
public class CaseSimpleObjGetter {
private int a;
@Hashed
private int b;
private int c;
CaseSimpleObjGetter(int a, int b, int c) {
this.a = a;
this.b = b;
this.c = c;
}
@Hashed
public int getA() {
return a;
}
protected int getB() {
return b;
}
protected int getC() {
return c;
}
}
我想实现一个提取器,它将从类似对象中提取所有可访问的字段。
特别是,我想访问注释信息。
我想知道,实现该提取器的最佳方法是什么?
在此示例中,我想提取 (a, b, c) 的名称和值,并知道哪些使用 @Hashed 注释进行了注释。
我以前使用过 BeanWrapperImpl(来自 spring)和 Introspector。
但是,我找不到从属性访问注释的方法。
bean 中实际上是否允许注释?
解决方案
推荐阅读
- excel - 输入 excel 数据重叠的 Web 占位符问题
- docker - Nginx 重定向 https->http(反向代理)->port(docker 容器)
- cvxpy - 将优化问题从 CVX 转换为 CVXPY?
- c# - 使用工厂方法创建类型化 HTTP 客户端,ASP.NET Core 2.1
- nginx - NGINX 将所有与 URL 匹配的请求重定向到子域
- corda - 无法使用 IntelliJ IDEA 导入 sumCash
- reactjs - 如何在 redux 操作调度调用中返回一个承诺,以便我可以链接 .then 块?
- javascript - 文本跨度仅在鼠标悬停后呈现
- c++ - 模板类型之间的隐式转换
- jquery - 通过 Reactjs -Jquery 单击时,Unshift 函数会创建其他按钮