struts注解@Result是否应该只在class级别?
Should struts annotation @Result only be in class level or not?
我正在阅读 Struts2 文档,发现其文档中存在某种矛盾。在这个linkhttps://struts.apache.org/docs/convention-plugin.html
The Convention plugin allows action classes to define different results for an action. Results fall into two categories, global and local. Global results are shared across all actions defined within the action class. These results are defined as annotations on the action class. Local results apply only to the action method they are defined on
然而,在另一个link、https://struts.apache.org/docs/result-annotation.html中建议:
The @Result annotation lives at the Action class level and not the method level. This matches what is found in an XML-based Action configuration. Do not be tempted to annotate your Action's methods; it will not work.
那么哪个是正确的? @Result
可以在方法级别定义吗?
使用 @Action
属性 将本地结果配置为操作配置。换句话说,本地结果是在允许的地方配置的。使用 @Action
注释指定 属性 results
列表。您可以在此处添加 @Result
注释。
Dave Newton 的书有一段摘录"Apache Struts 2 Web Application Development":
We can also configure results with Convention's annotations. We don't
have to rely on the Convention plug-in's idea of what our result JSP
files should be named. We can define results manually using the
@Result
annotation, and the @Results
annotation if we need multiple
results. (We can use the @Results
annotation only at the class
level, while the @Action
and @Actions
annotations are available at
the method level. We can define multiple results at the action level
via the @Action
annotation's results
property.)
wiki 定义也正确
Global results are shared across all actions defined within the action class. These results are defined as annotations on the action class. Local results apply only to the action method they are defined on. Here is an example of the different types of result annotations:
com.example.actions.HelloWorld
package com.example.actions;
import com.opensymphony.xwork2.ActionSupport;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Actions;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;
@Results({
@Result(name="failure", location="fail.jsp")
})
public class HelloWorld extends ActionSupport {
@Action(value="/different/url",
results={@Result(name="success", location="http://struts.apache.org", type="redirect")}
)
public String execute() {
return SUCCESS;
}
@Action("/another/url")
public String doSomething() {
return SUCCESS;
}
}
我正在阅读 Struts2 文档,发现其文档中存在某种矛盾。在这个linkhttps://struts.apache.org/docs/convention-plugin.html
The Convention plugin allows action classes to define different results for an action. Results fall into two categories, global and local. Global results are shared across all actions defined within the action class. These results are defined as annotations on the action class. Local results apply only to the action method they are defined on
然而,在另一个link、https://struts.apache.org/docs/result-annotation.html中建议:
The @Result annotation lives at the Action class level and not the method level. This matches what is found in an XML-based Action configuration. Do not be tempted to annotate your Action's methods; it will not work.
那么哪个是正确的? @Result
可以在方法级别定义吗?
使用 @Action
属性 将本地结果配置为操作配置。换句话说,本地结果是在允许的地方配置的。使用 @Action
注释指定 属性 results
列表。您可以在此处添加 @Result
注释。
Dave Newton 的书有一段摘录"Apache Struts 2 Web Application Development":
We can also configure results with Convention's annotations. We don't have to rely on the Convention plug-in's idea of what our result JSP files should be named. We can define results manually using the
@Result
annotation, and the@Results
annotation if we need multiple results. (We can use the@Results
annotation only at the class level, while the@Action
and@Actions
annotations are available at the method level. We can define multiple results at the action level via the@Action
annotation'sresults
property.)
wiki 定义也正确
Global results are shared across all actions defined within the action class. These results are defined as annotations on the action class. Local results apply only to the action method they are defined on. Here is an example of the different types of result annotations:
com.example.actions.HelloWorld
package com.example.actions; import com.opensymphony.xwork2.ActionSupport; import org.apache.struts2.convention.annotation.Action; import org.apache.struts2.convention.annotation.Actions; import org.apache.struts2.convention.annotation.Result; import org.apache.struts2.convention.annotation.Results; @Results({ @Result(name="failure", location="fail.jsp") }) public class HelloWorld extends ActionSupport { @Action(value="/different/url", results={@Result(name="success", location="http://struts.apache.org", type="redirect")} ) public String execute() { return SUCCESS; } @Action("/another/url") public String doSomething() { return SUCCESS; } }