About Bean.java Feature Introduction
· JavaBean is a reusable component developed using the Java language, which can be used to reduce duplication of code in the development of JSP and to make the development of the entire JSP code more concise.
Personal understanding: Bean.java is a class that contains some private variables and public methods.
Below through the e-commerce website Management system in the commodity order simple introduction bean.
1 PackageCom.oracle.jsp.bean;2 /**3 * Commodity Order Bean4 * @authorSvson5 *6 */7 Public classOrderproductbean {8 Private intID;9 Private intorderId;Ten PrivateOrderbean Orderbean; One Private intproductId; A PrivateProductbean Productbean; - Private floatPrice ; - Private intNumber ; the PrivateString datetime;
- PublicOrderproductbean () {//non-parametric null method - } - PublicOrderproductbean (Productbean Productbean,intNumber ) {//order for single commodity and quantity + This. Setproductbean (Productbean); - This. Setnumber (number); + } A PublicOrderproductbean (Orderbean orderbean, ProductbeanProductbean,intNumber ) {//Multiple orders for goods and quantities. - This. Setorderbean (Orderbean); These three tectonic methods belong to the hierarchical progressive relationship. corresponding to the customer purchase mode in different situations - This. Setproductbean (Productbean); - This. Setnumber (number); - } - Public intgetId () { in returnID; - } to Public voidSetId (intID) { + This. ID =ID; - } the Public intGetorderid () { * returnorderId; $ }Panax Notoginseng Public voidSetorderid (intorderId) { - This. OrderId =orderId; the } + PublicOrderbean Getorderbean () { AreturnOrderbean; the } + Public voidSetorderbean (Orderbean orderbean) { - This. Orderbean =Orderbean; $ } $ Public intGetProductID () { - returnproductId; - } the Public voidSetproductid (intproductId) { - This. ProductId =productId;Wuyi } the PublicProductbean Getproductbean () { - returnProductbean; Wu } - Public voidSetproductbean (Productbean productbean) { About This. Productbean =Productbean; $ } - Public floatGetPrice () { - returnPrice ; - } A Public voidSetprice (floatPrice ) { + This. Price =Price ; the } - Public intGetNumber () { $ returnNumber ; the } the Public voidSetnumber (intNumber ) { the This. Number =Number ; the } - PublicString GetDateTime () { in returndatetime; the } the Public voidsetdatetime (String datetime) { About This. datetime =datetime; the } the}
Related questions explained:
Why must there be a get set method in 1:bean?
Simply put, a bean is the purpose of assigning and taking values through these get set methods.
A simple bean contains a private variable (encapsulating Protection Code privacy) and the associated public get set method. At this point the bean is equivalent to a black box with set get, and the user simply calls these methods to complete the encapsulation operation.
2:bean Why must there be an empty method with no parameters?
Java beans are often used in containers or frameworks (such as spring), and many of these containers or frameworks need to be constructed using reflection (reflect) to implement Java Bean objects, which can be cumbersome to configure or use if there is no default constructor without parameters.
The default construction method is required when instantiating the class, as follows:
Orderproductbean orderproductbean= New Orderproductbean ();
A brief introduction to Bean.java!