`
fannyxjf
  • 浏览: 105432 次
  • 性别: Icon_minigender_2
  • 来自: 武汉
社区版块
存档分类
最新评论

Struts2 Result Annotation传参

阅读更多

在Struts的官方网站上有如下说明:

@Result Annotation Parameters

  • name - Result name; default Action.SUCCESS
  • value - Value of result (result destination)
  • type - Type of result; default NullResult. For example:
    • ServletRedirectResult
    • ServletActionRedirectResult - Equivalent to redirect-action type in XML config.
    • TilesResult
  • params - An Array of the parameters in the form {key1, value1, key2, value2}

可知@Result是可以传参的,然而网上很多例子都只是传常量参数,但实际应用中往往需要传变量。其实可以这样写:

@Action(value = "/admin/info/edit", results = {@Result(name = "success", location = "show", params={"id", "${id}"}, type="redirectAction") })
public String edit(){

    ......

}

 

其实跟写xml配置是类似的。

<action name="actionName!*" class="actionClass" method="{1}">
    <result name="show" type="redirectAction">show?id=${id}</result>
</action>

 

顺便一提,在xml配置中,result里的路径注意不要带.action这样的后缀名,而且不能用类似<param name="id">${id}</param>这样的方式传参,不过这个bug已经将会在struts2.1.7中修复,详见https://issues.apache.org/struts/browse/WW-1714

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics