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.