对于methodName 和resultName的区别很迷惑,查了很多资料都不得其解
最后在API中找到答案
引用
(1)Marks a action method that if it's not validated by ValidationInterceptor then execute input method or input result.
Annotation usage: The InputConfig annotation can be applied at method level.
Annotation parameters:
Parameter Required Default Notes
methodName no (2)execute this method if specific
resultName no (3)return this result if methodName not specific
(1)当验证方法没有通过时,改变默认返回的input视图
(2) 执行指定的方法
(3)返回result 如果methodName 没有指定
废话少说 上代码
- public class StudentAction extends ActionSupport {
- @InputConfig(methodName="input2",resultName="resultTest")
- public String inputConfigTest2(){
- return INPUT;
- }
- public void validateInputConfigTest2(){
- addFieldError("ss", "main validateInputConfigTest2");
- //validate方法在遇到 addFieldError方法时会自动返回input视图
- }
- public String input2(){
- return "test";
- }
- }
- <span style="font-size: medium;">public class StudentAction extends ActionSupport {
- @InputConfig(methodName="input2",resultName="resultTest")
- public String inputConfigTest2(){
- return INPUT;
- }
- public void validateInputConfigTest2(){
- addFieldError("ss", "main validateInputConfigTest2");
- //validate方法在遇到 addFieldError方法时会自动返回input视图
- }
- public String input2(){
- return "test";
- }
- }
- </span>
@InputConfig(methodName="input2",resultName="resultTest") 的作用是改变默认返回的input视图 API中可查
resultName只有在methodName没写如@InputConfig(resultName="resultTest") 时才起做用
Jsp页面
- <%@taglib prefix="s" uri="/struts-tags" %>//导入struts2标签
- <body>
- <s:fielderror/>
- inputconfig test
- </body>
- <span style="font-size: medium;"><%@taglib prefix="s" uri="/struts-tags" %>//导入struts2标签
- <body>
- <s:fielderror/>
- inputconfig test
- </body>
- </span>
上述代码只写了少部分 请自己配置 Action 并测试
调用方法 如 http://localhost:8080/struts2test10/studentAction!inputConfigTest2
相关推荐
struts2 annotation 注解的详细介绍及使用方法
博文链接:https://flym.iteye.com/blog/174358
参考博文:http://blog.csdn.net/u011638419/article/details/41743049
struts2 使用Annotation配置实现的小例子,转载供大家学习使用,里面包括了所需的jar包
struts2,json-plugin, 并全注解零配置
struts2-Annotation
马士兵视频里的struts2 hibernate3 spring2.5 annotation 整合 绝对好用 里面还有jar包 部署就可以用
Struts2的“零配置”特性是Struts2的新功能,可能会出现一些小Bug,所以企业开发者请慎重使用该特性, ...如果用的是Annotation的Struts2,就要将struts.xml去掉,否则即使将struts.xml中的内容注销,也会报错;
通过产生临时文件下载之后,再通过线程删除临时文件
前段时间很困惑的文件下载问题,现贴出代码,希望能帮到需要的人吧
Annotation自定义地图上的Annotation,在Annotation上加入图片。
本文档对利用struts2 注解 annotation 实现文件下载作了简单介绍,并有代码为例,希望对学习struts2注解annotation的人有帮助,特别是需要动态传参方面。
用注解(annotation)方式配置struts2 (webwork) 中action的拦截器(interceptor)
struts annotation.ppt 欢迎下载
自定义Annotation的例子,博客地址:http://blog.csdn.net/yirentianran/article/details/52816764
NULL 博文链接:https://zhenghuazhi.iteye.com/blog/1467214
Struts2 Spring Hibernate 框架整合 Annotation Maven project