在原来的webwork式的xml配置文件里可以给<action>下的<result>节点添加一些额外的参数。
<result ..> <param name="">...</param></result>那换成@Result annotation之后要怎么做呢。
看@Result的源代码发现有个params的String数组
@Retention(RetentionPolicy.RUNTIME)public @interface Result { String name() default Action.SUCCESS; Class type() default NullResult.class; String value(); String[] params() default {};}
可是原来的param配置是个key和value的键值对啊。后来查到struts2的文档原来就这个String数组里约定的是key,value,这样的顺序。
•params - An Array of the parameters in the form {key1, value1, key2, value2}
@Result(name="error",type=FreemarkerResult.class, value="/error.ftl", params={"contentType", "application/xml"})
其实上面的大家都知道,问题是想传传参数该怎么办呢?
其中key 是可以随便写的,后面的直接使用action 中的带有set方法的变量就ok了
如:params={"key","fileId"})
fileId 为action中的一个带set 方法的变量
@Result(name="success",
type="redirectAction",
location="d-list",
params={"id", "%{id}"}
)
这样,当return SUCCESS时,就会跳转至d-list?id=XXXX
分享到:
相关推荐
本文档对利用struts2 注解 annotation 实现文件下载作了简单介绍,并有代码为例,希望对学习struts2注解annotation的人有帮助,特别是需要动态传参方面。
struts2 annotation 注解的详细介绍及使用方法
struts2 使用Annotation配置实现的小例子,转载供大家学习使用,里面包括了所需的jar包
spring项目启动报错,@EnableAsync annotation metadata was not injected日志
struts2-Annotation
博文链接:https://flym.iteye.com/blog/174358
马士兵视频里的struts2 hibernate3 spring2.5 annotation 整合 绝对好用 里面还有jar包 部署就可以用
参考博文:http://blog.csdn.net/u011638419/article/details/41743049
spring2.5 ibatis2.3 struts2.1 dwr3 annotation集成配置
用注解(annotation)方式配置struts2 (webwork) 中action的拦截器(interceptor)
struts2,json-plugin, 并全注解零配置
Struts2 Spring Hibernate 框架整合 Annotation Maven project
Struts2 Spring Hibernate 框架整合 Annotation Maven project.zip
Struts2中使用annotation实现零配置
本文带来的案例是:打印Log,主要介绍@Pointcut切点表达式的@annotation方式,以及 五种通知Advice注解:@Before、@After、@AfterRunning、@AfterThrowing、@Around。 本资源是@Pointcut使用@annotation的方式,结合...
struts2 spring2.5 hibernate3.0 annotation 整合
NULL 博文链接:https://vincenta.iteye.com/blog/1535330
Struts2+Spring2+Hibernate3+Annotation所需JAR包
1、shiro+strut2 2、shiro注解 + struts2注解 2、shiro 缓存:因为使用了缓存,第一使用admin登录,如果没有logout,再用test登录,则test具有admin的权限
Struts2的“零配置”特性是Struts2的新功能,可能会出现一些小Bug,所以企业开发者请慎重使用该特性, ...如果用的是Annotation的Struts2,就要将struts.xml去掉,否则即使将struts.xml中的内容注销,也会报错;