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

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

// 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规范说:

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 Specification,该属性名称应为[MCount]。但是,如果我按如下方式使用[PropertyPath.from](将调用PropertyPath构造函数)来获取属性,则将收到以下异常,因为属性名称已更改为[mCount]。

PropertyPath property = PropertyPath.from("MCount", classType);


例外:
    java.lang.IllegalArgumentException:无法使用
    在此ManagedType [class]上给定名称[mCount] ...

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

最佳答案

the commit 0c4ed8a86a引入了此行为,以修复仅与所有大写属性名称有关的DATACMNS-257

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

10-06 05:44