In Struts2, the HTML form will be mapped directly to a POJO, with the params interceptor, the corresponding attribute defined in the class, and the corresponding set method.
The params interceptor assigns the value of the request parameter to each property of the top object of the stack, and if the top object does not have a corresponding attribute, look down to the corresponding property of the next object.
If you already have a javabean, the table only son over the Bean's properties, you do not need to write again in the Action of the bean each property to assign a value, you can directly write a bean variable, through the Modeldriven interceptor, if the action class implements the The Modeldriven interface, which places the object returned by the Getmodel () method of the Modeldriven interface on top of the stack, and then the params interceptor assigns the form attribute to the empty bean object at the top of the stack. This is written after the interface is inherited (can have no Setemployee method)
1 Private employee employee; 2 @Override 3 Public Employee Getmodel () {4 New Employee (); 5 return employee; 6 }
View Code
The code cannot return directly to new employee () because it is not the same as the member variable employee, so it is empty when the employee object is used.
Every plea, as long as there is Modeldriven Getmodel () method, the general stack top object will be the object returned by the method!
With the Class.hashcode () method, you can see that the object is not the same.
About Echo:
From the top of the value stack, find the matching property, and if found, add it to the Value property and it will be automatically assigned.
29. 18
Struts2 Notes (2)