所谓间接实现零配置,是指只要做些初始化的配置之后,在以后的开发中基本上不用再对每个Action做配置
struts.xml这样配置
代码
- <action name="*/*" method="{2}" class="workbench.web.actions.{1}Action">
- <result name="custom">/view/{1}/${target}.jsp</result>
- </action>
<script>render_code();</script>
struts.properties的配置:
代码
- struts.objectFactory = spring
- struts.objectFactory.spring.autoWire = name
- struts.devMode = true
- struts.enable.DynamicMethodInvocation = false
- struts.action.extension =
- struts.enable.SlashesInActionNames = true
<script>render_code();</script>
然后写一个BaseAction:
代码
- public abstract class BaseAction {
- protected final String CUSTOM = "custom";
- private String target;
- protected final Log logger = LogFactory.getLog(getClass());
- public String getTarget() {
- return target;
- }
- public void setTarget(String target) {
- this.target = target;
- }
-
- protected String render(String _target){
- setTarget(_target);
- return CUSTOM;
- }
- }
<script>render_code();</script>
这样其余的Action都可以直接继承BaseAction,不用再做任何配置
通过return render(target)转发到指定的jsp页面,从而间接实现零配置
代码
- public class UserAction extends BaseAction{
- private User user;
- private UserService userService;
- public void setUserService(UserService userService) {
- this.userService = userService;
- }
-
- public User getUser() {
- return user;
- }
- public void setUser(User user) {
- this.user = user;
- }
- public String test(){
- user = userService.get(1l);
- return render("test");
- }
- }
分享到:
相关推荐
简述STRUTS2_Convention零配置
struts-convention实现零配置
struts2采用convention-plugin实现零配置,希望大家用的到!
Struts2中使用annotation实现零配置
STRUTS2:零配置插件CodeBehind
Struts-Convention实现零配置,可直接部署运行,主要针对于新手,很简单的一个项目,内有说明:explanation.txt
默认包路径包含action,actions,struts,struts2的所有包都会被struts作为含有Action类的路径来搜索。你可以通过设置struts.convention.package.locators属性来修改这个配置。如: <constant name="struts.convention....
javaEE学习阶段,struts2初步使用环境配置。 javaEE学习阶段,struts2初步使用环境配置。
struts2实现表单数据校验 struts2的基石-拦截器 struts2中实现IOC struts2中实现文件上传 struts2中实现CRUD struts2中的OGNL struts2的新表单标志的使用 struts2与AJAX一 struts2与AJAX二 struts2与AJAX三 struts2...
struts2配置文件以及代码示例struts2配置文件以及代码示例struts2配置文件以及代码示例struts2配置文件以及代码示例struts2配置文件以及代码示例struts2配置文件以及代码示例struts2配置文件以及代码示例struts2配置...
从struts2.1开始,struts2不再推荐使用Codebehind作为零配置插件,而是改为使用Convention插件来支持零配置,和Codebehind相比,Convention插件更彻底,该插件完全抛弃配置信息,不仅不需要是使用struts.xml文件进行...
如何使用插件convention来实现struts2框架的零配置以及整合ssh架构
struts2配置过滤器 示例代码
从struts2.1开始,struts2不再推荐使用Codebehind作为零配置插件,而是改为使用Convention插件来支持零配置,和Codebehind相比,Convention插件更彻底,该插件完全抛弃配置信息,不仅不需要是使用struts.xml文件进行...
NULL 博文链接:https://username2.iteye.com/blog/1817573
struts2 配置文件 jar 包括web.xml struts.xml