所谓间接实现零配置,是指只要做些初始化的配置之后,在以后的开发中基本上不用在对每个Action做配置 struts.xml这样配置
<action name="*/*" method="{2}" class="workbench.web.actions.{1}Action">
<result name="custom">/view/{1}/${target}.jsp</result>
</action>struts.properties的配置:
XML codestruts.objectFactory = spring
struts.objectFactory.spring.autoWire = name
struts.devMode = true
struts.enable.DynamicMethodInvocation = false
struts.action.extension =
struts.enable.SlashesInActionNames = true然后写一个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;
}
}
这样其余的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");
}
}
posted on 2008-08-01 15:45
Hank1026 阅读(331)
评论(0) 编辑 收藏 所属分类:
每日积累