Java Bean Naming conventions

Source: Internet
Author: User

Write an add function in the SSH framework and find that a field in the database has not changed. The page data is uploaded to the background, and I use Ajax Serialization. So I printed the serialized data, found that the page data is not a problem, but when the data after the background of the action inside, the direction of the private int pcount; This value is 0. this data has not been transmitted, the display is 0. This is a little Awkward.

Because do not know where this problem appears, so through baidu, Baidu above the countless materials to view the relevant Issues. Through the long baidu. Finally found the problem, the original is my name for this field has been a problem.

Online said:JavaBean property naming as far as possible using the regular Camel-style naming rules.

at that time wrote the private int pcount. and uses the functions inside the myeclipse to generate its get and set METHODS. Look at the generated method:

If the JavaBean attribute is named as much as possible, use the regular Hump-style naming conventions to see if you're going to have a problem with directions. Rules:

1. for general properties <PropertyName>, The first word of the property name is lowercase and the number of letters is greater than 1, and the first letter of the second word is Capitalized. The corresponding Getter/setter method is named:get/set + <PropertyName> (), that is, the first word of the attribute name is capitalized, preceded by a "get" or The "set" prefix.

2. for Boolean type <propertyname>, You can write the getter/setter method According to the rules of the general attribute, the Getter method can use is + < the form of propertyname> () Instead.

3. for Unconventional properties <PName, the first word of the property name is lowercase and the number of letters equals 1, and the second word is Capitalized.

This will reveal the Problem. The first letter of the generated get and set methods except Get/set must be capitalized, and here is the lowercase, which will cause the previous problem that the Page's parameters cannot be passed to the Action.

Need to avoid: attribute name the first word try to avoid using a letter: such as Pcount.
Boolean property name avoid names that start with "is"

Java Bean Naming conventions

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.