读书人

struts2采取convention-plugin实现零配

发布时间: 2012-10-27 10:42:26 作者: rapoo

struts2采用convention-plugin实现零配置(转)
零配置并不是没有配置,而是通过约定大于配置的方式,大量通过约定来调度页面的跳转而使得配置大大减少。所以,首先应该了解下convention-plugin的约定:
1. 默认所有的结果页面都存储在WEB-INF/content下,你可以通过设置struts.convention.result.path这个属性的值来改变到其他路径。如:URL Result
File that could match Result Type /hellosuccess/WEB-INF/content/hello.jspDispatcher/hellosuccess/WEB-INF/content/hello-success.htm Dispatcher/hellosuccess/WEB-INF/content/hello.ftl FreeMarker/hello-worldinput/WEB-INF/content/hello-world-input.vmVelocity/test1/test2/helloerror/WEB-INF/content/test/test2/hello-error.htmlDispatcher

?

?

?

?

?

?

?

?

?

以上的内容来自struts2的文档http://struts.apache.org/2.1.6/docs/convention-plugin.html

?

当然,简单的通过默认的方式来进行配置不能完全满足实际项目的需要。所幸,convention的零配置是非常灵活的。
通过@Action注释
对如下例子:

方法名 默认调用路径 默认映射路径 method1 /hello!method1.action . /WEB-INF/content/hello.jsp method2 /hello!method2.action. /WEB-INF/content/hello.jsp

通过@Action注释后

方法名 @Action注释后调用路径 @Action注释 后映射路径 method1 /action1!method1.action. /WEB-INF/content/action1.jsp method1 /user/action2!method2.action /WEB-INF/content/user/action2.jsp


通过@Actions注释

读书人网 >软件架构设计

热点推荐