分类:
2008-09-11 14:33:55
所谓间接实现零配置,是指只要做些初始化的配置之后,在以后的开发中基本上不用在对每个Action做配置 struts.xml这样配置
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");
}
}