-- Selected from ibatis SQL MAPS Development Guide
Java Bean simple tutorial
The sqlmap architecture requires a solid understanding of Java Beans. Fortunately, there are not many Java Bean APIs related to sqlmap. Therefore, if you have never touched Java Bean before, the following is a brief introduction.
What is Java Bean? Java Bean is a special Java class. it strictly complies with the naming rules of JavaBean and defines the naming rules for access class status information methods.
Java Bean attributes are defined by its methods (rather than by fields ). The method starting with "set" is a writable attribute, while the method starting with "get" is a readable attribute.
For fields of the "Boolean" type, the readable method name can also start with "is. The "set" method should not have a return type (that is, it must be void) and can only have one parameter. The data type of the parameter must be the same as the data type of the attribute. The "get" method should return an appropriate type and no parameters are allowed.
Although not mandatory, the Data Type of the "set" method parameter must be the same as that of the "get" method. Java Bean should also implement the serializable interface.
Java Bean also supports other features (such as events ). However, these features are not important in SQL map and Web applications.
The following is an example of Java Bean:
Public class product implements serializable ...{
Private string ID;
Private string description;
Public String GETID ()...{
Return ID;
}
Public void setid (string ID )...{
This. ID = ID;
}
Public String getdescription ()...{
Return description;
}
Public void setdescription (string description )...{
This. Description = description;
}
Note! Do not confuse the Data Types of the "get" method and "set" method with specific attributes. For example
In the "Account" attribute of the value type, make sure that the getter method and setter method use the same value type, as shown in the following example:
Public void setaccount (int acct ){....}
Public int getaccount (){....}
Note that both methods use the "int" type. If the "long" type is returned from the "get" method
Problem.
Note! Similarly, you must have only one "get" method and one "set" method. Be judicious with polymorphic
Methods. You're better off naming them more specifically anyway.
Note! For properties of the "Boolean" type, the "Get" method can also have other syntaxes, which can be "isxxxx ()"
Format. Make sure that you only have one "is" method or "get" method. You cannot write either method at the same time.
Congratulations, you have completed this Java Bean tutorial.