Struts2 domain model (domain model ).

Source: Internet
Author: User

To avoid having too many classes in action, you need to write a lot of get (). Set (). Therefore, struts2 uses the domain model.

Eg:

Private user;
Public String add (){
System. Out. println ("name:" + User. getuname ());
System. Out. println ("PWD:" + User. getpwd ());
System. Out. println ("student added successfully ");
Return success;
}

Public user getuser (){
Return user;
}
Public void setuser (User user ){
This. User = user;
}

Writing JavaBean on the model layer is also part of the MVC idea. JavaBean eg:

 

Private string uname;

Private string PWD;

/*
* Set () Get ()
*/

Public void setuname (string uname ){
This. uname = uname;
}
Public String getpwd (){
Return PWD;
}

// Constructor
Public user (){
Super ();
}

In this way, you can directly access the project URL http: // localhost: 8080/hellouser/user! ADD? User. uname = A & User. Pwd = AAAA.

PS: the existence of parameters. Values are assigned to an object and operation objects are stored in the database.

PS2: DTO, data transfer object, which exists. When the parameter passed to the background does not match the domain model, process the parameter, operate the data, and pass it to the domain model.

 

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.