JavaBean 属性命名约定在哪里定义?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1991316/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Where is the JavaBean property naming convention defined?
提问by deamon
The Spring Framework APIdoc says:
在Spring框架API医生说:
The convention used is to return the uncapitalized short name of the Class, according to JavaBeans property naming rules: So, com.myapp.Product becomes product; com.myapp.MyProduct becomes myProduct; com.myapp.UKProduct becomes UKProduct.
使用的约定是返回类的未大写的短名称,根据JavaBeans属性命名规则:所以,com.myapp.Product变成product;com.myapp.MyProduct 变成 myProduct;com.myapp.UKProduct 变成 UKProduct。
I looked at Suns website to find a definition, but didn't find one. I wonder about a rule for names with more than one upper case character at the beginning. Is the rule that the first character is upper case if the second character is upper case too?
我查看了 Suns 网站以找到定义,但没有找到。我想知道开头有多个大写字符的名称的规则。如果第二个字符也是大写,那么第一个字符也是大写的规则是什么?
The background is, that I want to generate variable names automatically for use in HTML templates depending on the type of the object. Example: class: SomeName --> object: someName.
背景是,我想根据对象的类型自动生成变量名以在 HTML 模板中使用。示例:类:SomeName --> 对象:someName。
采纳答案by Carl Smotricz
http://download.oracle.com/otndocs/jcp/7224-javabeans-1.01-fr-spec-oth-JSpec/
http://download.oracle.com/otndocs/jcp/7224-javabeans-1.01-fr-spec-oth-JSpec/
http://www.oracle.com/technetwork/java/javase/tech/index-jsp-138795.html
http://www.oracle.com/technetwork/java/javase/tech/index-jsp-138795.html
Also, a direct link to the (PDF) specification.
此外,指向 (PDF) 规范的直接链接。
Section 8.8 in the linked document is entitled "Capitalization of inferred names" and briefly outlines how names of properties are derived.
链接文档中的第 8.8 节标题为“推断名称的大写”,并简要概述了属性名称的派生方式。
回答by Edward Q. Bridges
the implementation of this functionality is in this class: http://java.sun.com/javase/6/docs/api/java/beans/Introspector.html
此功能的实现在此类中:http: //java.sun.com/javase/6/docs/api/java/beans/Introspector.html