试图在 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
我需要获取如下的单个属性而不是 foreachproduct
除了通过数组,有没有什么方法可以直接访问它,类似于 Lombok,如下所示
var desc = Product.Fields.description
var name = Product.Fields.name
var price = Product.Fields.price
有什么办法可以做到这一点?