使用注解來配置Action的最大好處就是可以實現零配置
要使用注解方式
雖說是零配置的
<?xml version=
<!DOCTYPE struts PUBLIC
/dtds/struts
<struts>
<!
<constant name=
<!
<constant name=
<!
<constant name=
<!
<constant name=
<!
<constant name=
<!
<constant name=
<!
<constant name=
</struts>
action類的注解
package com
import ornvention
import ornvention
import ornvention
import ornvention
import ornvention
import ornvention
import ornvention
import com
/**
* Struts
*
*/
@ParentPackage(
@Namespace(
@Results( { @Result(name =
@Result(name =
@ExceptionMappings( { @ExceptionMapping(exception =
public class LoginAction extends ActionSupport {
private static final long serialVersionUID =
private String loginName;
private String password;
@Action(
public String login() throws Exception {
if (
return SUCCESS;
} else {
return ERROR;
}
}
@Action(value =
public String add() throws Exception {
return SUCCESS;
}
public String getLoginName() {
return loginName;
}
public void setLoginName(String loginName) {
this
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this
}
}
這樣就完成了一個基於注解的action配置
總結常用的注解如下
Namespace
ParentPackage
Result
Results
ResultPath
Action
Actions
ExceptionMapping
ExceptionMappings
InterceptorRef
InterceptorRefs
From:http://tw.wingwit.com/Article/program/Java/ky/201311/28552.html