在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
分享到:
相关推荐
struts2 使用Annotation配置实现的小例子,转载供大家学习使用,里面包括了所需的jar包
struts2-Annotation
博文链接:https://flym.iteye.com/blog/174358
参考博文:http://blog.csdn.net/u011638419/article/details/41743049
本文档对利用struts2 注解 annotation 实现文件下载作了简单介绍,并有代码为例,希望对学习struts2注解annotation的人有帮助,特别是需要动态传参方面。
struts2 annotation 注解的详细介绍及使用方法
用注解(annotation)方式配置struts2 (webwork) 中action的拦截器(interceptor)
NULL 博文链接:https://vincenta.iteye.com/blog/1535330
马士兵视频里的struts2 hibernate3 spring2.5 annotation 整合 绝对好用 里面还有jar包 部署就可以用
struts2,json-plugin, 并全注解零配置
Struts2的“零配置”特性是Struts2的新功能,可能会出现一些小Bug,所以企业开发者请慎重使用该特性, ...如果用的是Annotation的Struts2,就要将struts.xml去掉,否则即使将struts.xml中的内容注销,也会报错;
自己学Struts的注解,写的一个零配置小demo。 很简单很简单,只供新手学习。
通过产生临时文件下载之后,再通过线程删除临时文件
Struts2 Spring Hibernate 框架整合 Annotation Maven project
Struts2 Spring Hibernate 框架整合 Annotation Maven project.zip
org.apache.struts2.views.freemarker.FreemarkerResult 16 httpheader 16 控制特殊http行为的结果类型 16 org.apache.struts2.dispatcher.HttpHeaderResult 16 stream 16 向浏览器发送InputSream对象,通常用来处理...
前段时间很困惑的文件下载问题,现贴出代码,希望能帮到需要的人吧