【问题标题】:How to use Class getMethod with lombok @Data如何将 Class getMethod 与 lombok @Data 一起使用
【发布时间】:2020-11-21 16:02:11
【问题描述】:

我正在尝试使用 lombok @Data 调用 Class getMethod() 方法来调用模型的 getter,但我得到了 NoSuchMethod 异常。以下是我的课程:

模型类:

@Data
public class Claim {
    private String customerName;
}

用法:

Claim.class.get("getCustomerName", String.class)

例外:

Method threw 'java.lang.NoSuchMethodException' exception.

【问题讨论】:

    标签: java spring spring-boot lombok


    【解决方案1】:

    您可以使用以下代码:

    new PropertyDescriptor("customerName", claim.getClass()).getReadMethod().invoke(claim)
    

    为了更好的解释click here

    【讨论】:

      猜你喜欢
      • 2018-10-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-07-29
      • 2012-05-10
      • 1970-01-01
      • 2017-03-21
      相关资源
      最近更新 更多