JavaBean Specification Document: http://download.oracle.com/otndocs/jcp/7224-javabeans-1.01-fr-spec-oth-JSpec/
About the Property name section:
Utility method to take a string and convert it to normal Java variable name capitalization. This normally means converting the first character from upper case to lower case, but in the (unusual) special case when t Here's more than one character and both the first and second characters be upper case, we leave it alone.
Thus "Foobah" becomes "Foobah" and "X" becomes "X", but "url" stays as "url".
Tool translation + Personal modification:
The tool method puts a string and converts it to uppercase in the normal Java variable name. This usually means that the first character is converted from uppercase to lowercase,
However, in special cases where the current two characters or multiple characters are uppercase, we do not process him (return directly).
Therefore, "Foobah" becomes "Foobah" and "X" become "X", but "url" is still "url".
The above content is actually a java.bean.Introspector#decapitalize
Javadoc comment for this method.
Here's how:
/** * Utility method to take a string and convert it to normal Java variable * Name capitalization. This normally means converting the first * character from upper case to lower case, but in the (unusual) special * case WH En there is more than one character and both the first and * second characters be upper case, we leave it alone. * <p> * Thus "Foobah" becomes "Foobah" and "X" becomes "X", but "url" stays * as "url". * * @param name the string to be decapitalized. * @return The decapitalized version of the string. */public static string Decapitalize (string name) {if (name = = NULL | | name.length () = = 0) {return name; } if (Name.length () > 1 && character.isuppercase (Name.charat (1)) && Character.isu Ppercase (Name.charat (0))) {return name; } char chars[] = Name.tochararray (); Chars[0] = Character.tolowercase (chars[0]); return new String (chars);}
We use this method to test several different field names:
Look at the following code:
public class Testbean {public static void Main (string[] args) { System.out.println (introspector.decapitalize ( "Name")); System.out.println (Introspector.decapitalize ("Name")); System.out.println (Introspector.decapitalize ("Mname")); System.out.println (Introspector.decapitalize ("NAME"));} }
Output:
Name
Name
Mname
NAME
The result is the same as the results, that is, name
Name
if the field name is Name
, it will be name
used, so from this point of view the naming method is wrong and does not conform to the specification.
Mname is no problem. There is no problem with NAme, and name,name is not wrong.
This article says that depth may not be enough, and the setter and getter in the title are not mentioned at all. If you do not understand the place, welcome to leave a message!
In-depth understanding of attribute names and Setter/getter methods in the JavaBean specification