Struts2 Notes (2)

Source: Internet
Author: User

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)

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.