Struts2 應用程序可以使用Java5注釋來替代XML和Java屬性的配置。以下是與不同類別相關(guān)的最重要注釋的列表:
@Namespace("/content") public class Employee extends ActionSupport{ ... }
@Result(name="success", value="/success.jsp") public class Employee extends ActionSupport{ ... }
@Results({ @Result(name="success", value="/success.jsp"), @Result(name="error", value="/error.jsp") }) public class Employee extends ActionSupport{ ... }
public class Employee extends ActionSupport{ @After public void isValid() throws ValidationException { // validate model object, throw exception if failed } public String execute() { // perform secure action return SUCCESS; } }
public class Employee extends ActionSupport{ @Before public void isAuthorized() throws AuthenticationException { // authorize request, throw exception if failed } public String execute() { // perform secure action return SUCCESS; } }
public class Employee extends ActionSupport{ @BeforeResult public void isValid() throws ValidationException { // validate model object, throw exception if failed } public String execute() { // perform action return SUCCESS; } }
public class Employee extends ActionSupport{ @ConversionErrorFieldValidator(message = "Default message", key = "i18n.key", shortCircuit = true) public String getName() { return name; } }
public class Employee extends ActionSupport{ @DateRangeFieldValidator(message = "Default message", key = "i18n.key", shortCircuit = true, min = "2005/01/01", max = "2005/12/31") public String getDOB() { return dob; } }
public class Employee extends ActionSupport{ @DoubleRangeFieldValidator(message = "Default message", key = "i18n.key", shortCircuit = true, minInclusive = "0.123", maxInclusive = "99.987") public String getIncome() { return income; } }
public class Employee extends ActionSupport{ @EmailValidator(message = "Default message", key = "i18n.key", shortCircuit = true) public String getEmail() { return email; } }
@ExpressionValidator(message = "Default message", key = "i18n.key", shortCircuit = true, expression = "an OGNL expression" )
public class Employee extends ActionSupport{ @IntRangeFieldValidator(message = "Default message", key = "i18n.key", shortCircuit = true, min = "0", max = "42") public String getAge() { return age; } }
@RegexFieldValidator( key = "regex.field", expression = "yourregexp")
public class Employee extends ActionSupport{ @RequiredFieldValidator(message = "Default message", key = "i18n.key", shortCircuit = true) public String getAge() { return age; } }
public class Employee extends ActionSupport{ @RequiredStringValidator(message = "Default message", key = "i18n.key", shortCircuit = true, trim = true) public String getName() { return name; } }
public class Employee extends ActionSupport{ @StringLengthFieldValidator(message = "Default message", key = "i18n.key", shortCircuit = true, trim = true, minLength = "5", maxLength = "12") public String getName() { return name; } }
public class Employee extends ActionSupport{ @UrlValidator(message = "Default message", key = "i18n.key", shortCircuit = true) public String getURL() { return url; } }
public class Employee extends ActionSupport{ @Validations( requiredFields = {@RequiredFieldValidator(type = ValidatorType.SIMPLE, fieldName = "customfield", message = "You must enter a value for field.")}, requiredStrings = {@RequiredStringValidator(type = ValidatorType.SIMPLE, fieldName = "stringisrequired", message = "You must enter a value for string.")} ) public String getName() { return name; } }
@CustomValidator(type ="customValidatorName", fieldName = "myField")
@Conversion() public class ConversionAction implements Action { }
@CreateIfNull( value = true ) private List<User> users;
@Element( value = com.acme.User ) private List<User> userList;
@Key( value = java.lang.Long.class ) private Map<Long, User> userMap;
@KeyProperty( value = "userName" ) protected List<User> users = null;
@TypeConversion(rule = ConversionRule.COLLECTION, converter = "java.util.String") public void setUsers( List users ) { this.users = users; }
更多建議: