Struts2 specifies the generic type of the Set element and the struts2 set element.
Public class LoginAction implements Action {
Private List users;
Public void setUsers (List users ){
This. users = users;
}
Public List getUsers (){
Return this. users;
}
Public String execute () throws Exception {
Return "SUCCESS ";
}
}
For example, if we do not use generics, struts2 cannot know the type of the Set element in the users attribute of Action.
Struts2 allows developers to specify the type of the collection element through local type conversion files. The type conversion file is a common Properties (. * properties) file. The type conversion file provides the type conversion configuration information.
The file name of the type conversion file should be in the form of a ActionName-conversion.properties, where ActionName is the class name of the Action, followed by the-conversion. properties string is a fixed part. The type conversion file should be placed in the same location as the Action file.
For example, to provide a type conversion file for the preceding Action, create a new LoginAction-conversion.properties file under the same directory of the Action, and then add the key-value pair to the file
Element_users = com. test. domain. User
The Set element type of the users set attribute is com. test. domain. User.
For Map-type attributes, both the key type and value type of Map must be specified. To specify the key type of the Map type attribute, add the following items to the type conversion file:
Key _ <MapPropName >=< KeyType>
The Key is a fixed syntax, <MapPropName> is the attribute name of the Map type attribute, and the composite type specifies the fully qualified class name of the Map Key value.
To specify the value type of the Map attribute, add the following items to the local type conversion file:
Element _ <MapPropName >=< ValueType>
Element is a fixed syntax, and <MapPropName> is the attribute name of the Map type attribute. The composite type specifies the value of the Map attribute and deserves a fully qualified class name.