【问题标题】:Bean Spec and apache-commons-beanutils (capitalization of getter)Bean Spec 和 apache-commons-beanutils(getter 的大写)
【发布时间】:2012-12-14 10:51:12
【问题描述】:

我们有一个 Bean,其字段名为:

private String aBcde = ... ;

getter 是这样写的:

public String getABcde() {
    return aBcde;
}

但是

http://javasourcecode.org/html/open-source/commons-beanutils/commons-beanutils-1.8.0/org/apache/commons/beanutils/PropertyUtilsBean.java.html

报告“NoSuchMethodError”

问题:getter 的名称是错误的,还是 BeanUtils 中的错误?

请注意,这很好用:

public String getaBcde() {
  ...
}

【问题讨论】:

    标签: apache-commons-beanutils


    【解决方案1】:

    根据http://blog.950buy.com/article/javabean-specification-on-a-few-you-should-know/看来我的预期是错误的,

    public String getaBcde() {
      ...
    }
    

    是正确的。

    实际上,Bean Spec 说:

    “但是为了支持偶尔使用所有大写名称,我们检查名称的前两个字符是否都是大写的,如果是,则不要理会它。例如:

    • “FooBah”变成“fooBah”
    • “Z”变成“z”
    • “网址”变为“网址””

    所以在我的例子中,我有 getter“getABcde”,它映射到属性“ABcde”,参见。 URL 示例。

    【讨论】:

      猜你喜欢
      • 2018-01-02
      • 2011-11-14
      • 2017-06-14
      • 1970-01-01
      • 1970-01-01
      • 2013-01-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多