一般情况下,Java的属性变量名都以小写字母起头.但也存在特殊情况,需要大写字母开头.
JavaBean允许大写字母起头的属性变量名,不过必须满足"变量的前两个字母要么全部大写,要么全部小写"的要求.
如: brand, IDCode, IC, ICCard等,这些变量名都是合法的.
而iC, iCCard, iDCode等属性名则是非法的.
<bean id='foo' class="com.test.Foo">
<property name="iDCode" value="01010"/>
</bean>
Java 语言本身在不会报错,但Spring容器时将得到失败的结果:
Error setting property values; nested exception is org.springframework.
beans.NotWritablePropertyException:Invalid property 'iDCode' of bean class[....]:
Bean property 'iDCode' is not writable or has an invalid Setter method. Did you mena 'IDCode'?
Caused by: org.springframework.beans.NotWritablePropertyException:Invalid property 'iDCode' of bean class
本文介绍了JavaBean中属性变量的命名规范,强调了合法的属性名称必须以小写字母开始,特殊情况可以使用大写字母开始,但需遵循特定规则。同时通过示例展示了不合规的属性命名会导致Spring容器配置失败。
1315

被折叠的 条评论
为什么被折叠?



