The structs can be automatically encapsulated for parameters, which is also simple.
One, the action parameter is automatically encapsulated:
1, you can declare properties of public, accept parameters directly in the action class.
2, the attribute is also private, if it is private, you need to provide a setter method, you can also provide getter method as needed.
3,struts can automatically convert types, typically we pass string-type arguments, and struts can be converted to the default declared variable type
4, when invoking the API, the parameter name passed must be the same as the name declared in the action class.
public class Useraction extends Actionsupport {private static final long Serialversionuid = 1l;public String username;publ IC String pw;public Integer age;public Date birthday;private Double balance;public void setbalance (double balance) {this.b Alance = balance;} Public String Login () {//Get all Parameters System.out.println ("Login with Username:" + username + ", password:" + PW + ", Age:" + AG E + ", Birthday:" + birthday + ", Balance:" + balance); return SUCCESS;}}
Second, the type conversion of the parameter
From the above, the default struts2 can be automatically class-Simple conversion (eight basic types), but sometimes we want to convert to complex effects, this time, we need to write the converter.
Two ways: one is to implement the interface, and one is to inherit the class Defaulttypeconverter
Do not want to paste the code, reference:
8018419
The Java Web struts2 framework uses-action parameters for automatic encapsulation and type conversion