After several months of development in other languages, I forgot about it. I found a blog and sorted it out,1st and 2 most commonly used
1. Use Action attributes:
Define the parameters to be received in the action and provide the corresponding setter and getter. They are the same as the names of the submitted parameters and are not used for data type conversion.
You can use get and post for the corresponding submission methods, such as testaction? Name = Admin
For example:
View code
1 Public Class Testaction Extends Actionsupport { 2 Private Static Final Long Serialversionuid =-74641515109893325l ; 3 Private String name; 4 5 Public Void Execeute (){ 6 System. Out. println (name + ":" + Name ); 7 } 8 9 Public String getname (){ 10 Return Name; 11 } 12 13 Public Void Setname (string name ){ 14 This . Name = Name; 15 } 16 }
2. Use domainmodel:
There are not many attributes in the action, but the model used in the model layer is used to save an object. You can use get and post for the corresponding submission method,
For example, testaction? Resbananrc. Name = Admin
For example:
View code
1 Public Class Testaction Extends Actionsupport { 2 Private Static Final Long Serialversionuid =-74641515109893325l ; 3 Private Resbanrc; 4 5 Public Resbanrc getresbanrc (){ 6 Return Resbananrc; 7 } 8 9 Public Void Setresbananrc (resbanrc ){ 10 This . Resbananrc = Resbananrc; 11 } 12 13 Public Void Execeute (){ 14 System. Out. println ("name:" +Resbananrc. getname ()); 15 } 16 }
3. Use DTO -- Data Transmission object
It is used to receive parameters and PASS Parameters. It is not an object class in the project. For example, the user will use the confirmation password when registering, so you must first receive the Parameter
To create a user object. Parameters are submitted in the same domain model method.
Dto:
View code
1 Public Class Userdto { 2 Private String name; 3 Private String password; 4 Private String confirm; 5 6 Public String getname (){ 7 Return Name; 8 } 9 Public Void Setname (string name ){ 10 This . Name = Name; 11 } 12 Public String GetPassword (){ 13 Return Password; 14 } 15 Public Void Setpassword (string password ){ 16 This . Password = Password; 17 } 18 Public String getconfirm (){ 19 Return Confirm; 20 } 21 Public Void Setconfirm (string confirm ){ 22 This . Confirm = Confirm; 23 } 24 }
Action:
View code
1 Public Class TestactionExtends Actionsupport { 2 Private Static Final Long Serialversionuid =-74641515109893325l ; 3 Private Userdto; 4 5 Public Userdto getuserdto (){ 6 Return Userdto; 7 } 8 Public Void Setuserdto (userdto ){ 9 This . Userdto = Userdto; 10 } 11 Public Void Execeute (){ 12 System. Out. println ("name:" + Userdto. getname ()); 13 } 14 }
4. Use modeldriven:
When creating an action, the action implements the modeldriven interface, calls the GetModel () method of the interface, and obtains the relevant object.
You can use get and post for the corresponding submission methods, such as testaction? Name = Admin
View code
1 Public Class Testaction Extends Actionsupport Implements Modeldriven <resbananrc> { 2 Private Static Final Long Serialversionuid =-74641515109893325l ; 3 Private Resbananrc resbanrc = New Resbananrc (); // Here we need to manually add a new 4 5 Public Resbananrc GetModel (){ 6 Return Resbananrc; 7 } 8 Public Void Execeute (){ 9 System. Out. println ("name:" + Resbananrc. getname ()); 10 } 11 }
5. Use the request object:
This method is the same as the traditional JSP and other transmission parameters, that is, the request. getparameter ("") method is used.
View code
1 Public Class Testaction Extends Actionsupport { 2 Private Static Final Long Serialversionuid =-74641515109893325l ; 3 4 Public Void Execeute (){ 5 String name = Super . Getrequest (). getparameter ("paraname" ); 6 System. Out. println ("name:" + Name ); 7 } 8 }