首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >为什么PropertyPath构造函数中的propertyName不遵循Javabeans规范?

为什么PropertyPath构造函数中的propertyName不遵循Javabeans规范?
EN

Stack Overflow用户
提问于 2017-04-28 15:08:32
回答 1查看 111关注 0票数 2

PropertyPath类的构造函数中变量propertyName的名称似乎不符合JavaBeans规范(推断名称的8.8大写)。

https://github.com/spring-projects/spring-data-commons/blob/master/src/main/java/org/springframework/data/mapping/PropertyPath.java

代码语言:javascript
复制
// PropertyPath Code: lines 73:
PropertyPath(String name, TypeInformation<?> owningType, List<PropertyPath> base) {
...
    String propertyName = name.matches(ALL_UPPERCASE) ? name : StringUtils.uncapitalize(name);
...
}

该代码意味着当名称与ALL_UPPERCASE不匹配时,第一个大写字母将更改为小写。

但是JavaBeans规范说:

代码语言:javascript
复制
JavaBeans Specification

Thus when we extract a property or event name from the middle of an existing Java name, 
we normally convert the first character to lower case. 
However to support the occasional use of all upper-case names, we check if the first 
two characters of the name are both upper case and if so leave it alone. 
So for example,
    “FooBah” becomes “fooBah”
    “Z” becomes “z”
    “URL” becomes “URL”

例如:如果我在一个类中有一个名为MCount的属性,那么该属性的名称应该是符合JavaBeans规范的MCount。但是,如果我像下面这样使用PropertyPath.from来获取属性,我将得到以下异常,因为属性名称已更改为mCount。

代码语言:javascript
复制
PropertyPath property = PropertyPath.from("MCount", classType);

异常: java.lang.IllegalArgumentException:无法在此ManagedType类上找到具有给定名称mCount的属性...

有谁有好的意见吗?谢谢!

EN

回答 1

Stack Overflow用户

发布于 2017-04-28 18:43:07

这一行为是在the commit 0c4ed8a86a中引入的,目的是修复只与所有大写属性名称相关的DATACMNS-257

如果您认为这是一个错误,请将其归档到the issue tracker

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43674116

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档