struts2 convention-plugin实现零配置
零配置并不是没有配置,而是通过约定大于配置的方式,大量通过约定来调度页面的跳转而使得配置大大减少。使得Action等配置不必写在Struts.xml中。
convention-plugin的约定
1. 默认所有的结果页面都存储在WEB-INF/content下,你可以通过设置struts.convention.result.path这个属性的值来改变到其他路径。
<constant name="struts.convention.result.path" value="/WEB-INF/page" />
2. 默认包路径包含action,actions,struts,struts2的所有包都会被struts作为含有Action类的路径来搜索。
你可以通过设置struts.convention.package.locators属性来修改这个配置。
<constant name="struts.convention.package.locators" value="web,action" />
<!--包路径包含web和action的将被视为Action存在的路径来进行搜索。-->
3.Convention 从找到的package以及其子package中寻找 com.opensymphony.xwork2.Action 的实现以及以Action结尾的类
com.example.actions.MainAction
com.example.actions.products.Display (implements com.opensymphony.xwork2.Action)
4.Convention通过如下规则确定URL的具体资源部分:去掉类名的Action部分。然后将将每个分部的首字母转为小写,用’-’分割
可以自定义分隔符:
<constant name="struts.convention.action.name.separator" value="-" />
举例:
- UserAction->user
- UserDetailAction ->user-detail
- com.ustb.web.user.detail.UserDetailAction ->/WEB-INF/content/user/detail/user-detail.jsp
通过注解来配置
一个方法被@Action注释后,只是多了一种调用方式,而不是说覆盖了原来的调用方式
public class HelloAction extends ActionSupport {
@Action("action1")
//调用路径:/action1!method1.action
//映射路径: /WEB-INF/content/action1.jsp
public String method1() {
return SUCCESS;
}
//调用路径:/user/action2!method2.action
//映射路径: /WEB-INF/content/user/action2.jsp
@Action("/user/action2")
public String method2() {
return SUCCESS;
}
}
@Actions注释
public class HelloAction extends ActionSupport {
//可以通过两种路径调用注释方法,会映射到对应的文件
@Actions({
@Action("/different/url"), //调用:/different/url!method1.action 映射:/WEB-INF/content/different/url-error.jsp
@Action("/another/url") //调用:/another/url!method1.action 映射:/WEB-INF/content/another/url-error.jsp
})
public String method1() {
return “error”;
}
@Namespace 注释
@Namespace("/other") //记得加斜杠
public class HelloWorld extends ActionSupport {
// 调用:/other/hello-world!method1.action
public String method1() {
return “error”;
}
@Action("url")
// 调用:/other/url!method2.action
public String method2() {
return “error”;
}
@Action("/different/url")
// 调用:/different/url!method3.action
public String method3() {
return “error”;
}
}
@Result注释
public class HelloWorld extends ActionSupport {
@Action(
value="test01",
results={
@Result(
name="error",
location="/pages/test01/say-hello.jsp",
params={
"param1","${param1}",
"param2","${param2}"
}
)
}
)
public String AgentLogin() throws Exception{ }
}
struts2 convention-plugin实现零配置的更多相关文章
- Struts2 Convention Plugin ( struts2 零配置 )
Struts2 Convention Plugin ( struts2 零配置 ) convention-plugin 可以用来实现 struts2 的零配置.零配置的意思并不是说没有配置,而是通过约 ...
- struts2采用convention-plugin实现零配置
最近开始关注struts2的新特性,从这个版本开始,Struts开始使用convention-plugin代替codebehind-plugin来实现struts的零配置. 配置文件精简了,的确是简便 ...
- Convention插件 struts零配置
http://blog.csdn.net/spyjava/article/details/13631961系列课程使用 注解:http://www.yiibai.com/struts_2/struts ...
- 菜鸟学Struts2——零配置(Convention )
又是周末,继续Struts2的学习,之前学习了,Struts的原理,Actions以及Results,今天对对Struts的Convention Plugin进行学习,如下图: Struts Conv ...
- 从struts2.1开始Convention零配置
从struts2.1开始,struts2不再推荐使用Codebehind作为零配置插件,而是改为使用Convention插件来支持零配置,和Codebehind相比,Convention插件更彻底,该 ...
- struts2 Convention插件零配置,使用注解开发
从struts21开始,struts2不再推荐使用codebehind作为零配置插件,而是改用Convention插件来支持零配置.与以前相比较,Convention插件更彻底. 使用Conventi ...
- Struts2 注解零配置方法(convention插件使用)
最近接触到一个新的项目,是做一个使用S2SH的电子商务商城的二次开发.之前使用过S2SH,在此之前的项目中,Struts2 使用的是XML配置而这个项目是使用注解.在这个项目中,注解还不需要使用Act ...
- spring+hibernate+struts2零配置整合
说句实话,很久都没使用SSH开发项目了,但是出于各种原因,再次记录一下整合方式,纯注解零配置. 一.前期准备工作 gradle配置文件: group 'com.bdqn.lyrk.ssh.study' ...
- 13、零配置Struts2开发
Convention 插件 从 Struts 2.1 开始, Struts 可以使用 Convention 插件来支持零配置: Convention 插件完全抛弃配置信息, 不仅不需要使用 strut ...
- struts2使用Convention Plugin在weblogic上以war包部署时,找不到Action的解决办法
环境: struts 2.3.16.3 + Convention Plugin 2.3.16.3 实现零配置 现象:以文件夹方式部署在weblogic(10.3.3)上时一切正常,换成war包部署,运 ...
随机推荐
- www.nygwkt.com
南京宁阳制冷设备维修有限公司是专业从事厨房空调,http://www.nygwkt.com岗位空调制冷设备设计.制造.安装.改造.维修.保养的专业化公司.在南京享有很高的客户评论. 我们对南京宁阳制冷 ...
- bzoj 2705: [SDOI2012]Longge的问题 歐拉函數
2705: [SDOI2012]Longge的问题 Time Limit: 3 Sec Memory Limit: 128 MBSubmit: 1035 Solved: 669[Submit][S ...
- iPhone开发 - 常用库
iPhone开发 - 常用库 这里总结了iPhone开发者开发过程中可能需要的一些资源 如何用Facebook graphic api上传视频: http://developers.facebook. ...
- KMP字符串模式匹配详解(转)
来自CSDN A_B_C_ABC 网友 KMP字符串模式匹配通俗点说就是一种在一个字符串中定位另一个串的高效算法.简单匹配算法的时间复杂度为O(m*n);KMP匹配算法.可以证明它的时间复杂度 ...
- Let's go home
hdu1824:http://acm.hdu.edu.cn/showproblem.php?pid=1824 题意:中文题. 题解:这一题建边要考虑两个限制条件,一个是队伍内部的,就是假如说 a,b, ...
- Java语言基础(四) String和StringBuffer的区别
Java提供了两个字符串类:String和StringBuffer. String提供了数值不可变的字符串,而StringBuffer提供的字符串对象可以进行修改. 当知道字符数据要改变的时候就可以使 ...
- mongodb 查看数据库和表大小
1.查看数据库 > db.stats(); { "db" : "test", //当前数据库 "collections" : 3, / ...
- WIN10 + VS2015 + WDK10 + SDK10 + VM虚拟机驱动开发调试环境搭建
http://blog.csdn.net/qing666888/article/details/50858272#comments
- VC和VS调用Lua设置以及Lua C API使用。
通过c++调用lua 脚本, 环境VC++6.0 lua sdk 5.1.4 在调用前先认识几个函数.1.调用lua_open()将创建一个指向Lua解释器的指针.2. luaL_ope ...
- HDU-4972 A simple dynamic programming problem
http://acm.hdu.edu.cn/showproblem.php?pid=4972 ++和+1还是有区别的,不可大意. A simple dynamic programming proble ...