问题描述
试图在Micronaut应用程序中获取POJO属性名称。我有下面的POJO课
@Introspected
public class Product {
@BsonProperty("_id")
@BsonId
private ObjectId id;
private String name;
private float price;
private String description;
// Getter and setter
}
我知道我们可以使用Introspected
final BeanIntrospection<Product> introspection = BeanIntrospection.getIntrospection(Product.class);
var product = introspection.getPropertyNames();
[0] name
[1] price
[2] description
上进行foreach
除了通过数组之外,还有什么方法可以直接访问它,类似于下面的Lombok
var desc = Product.Fields.description
var name = Product.Fields.name
var price = Product.Fields.price
有什么办法可以做到这一点?
解决方法
有没有办法访问数组,而不是通过数组 与龙目岛直接相似,如下所示:
var desc = Product.Fields.description
var name = Product.Fields.name
var price = Product.Fields.price
不。没有这样的API来支持这样的语法。