struts2中用dto域模型接收前台传来的参数,需实现ModelDriven<**>接口,并实现getModel()方法将dto具体实现对象返回
package bbs.action;
import java.util.List;
import java.util.Map;
import javax.annotation.Resource;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import bbs.model.User;
import bbs.service.UserManager;
import bbs.vo.UserVo;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
@Component("login")
@Scope("prototype")
public class LoginAction extends ActionSupport implements ModelDriven<UserVo> {
private Map request;
private Map session;
private Map application;
private UserManager userManager;
private UserVo uservo = new UserVo();
public LoginAction() {
request = (Map) ActionContext.getContext().get("request");
session = ActionContext.getContext().getSession();
application = ActionContext.getContext().getApplication();
}
public UserVo getModel() {
return uservo;
}
@Override
public String execute() throws Exception {
System.out.println(uservo.getUsername());
return "success";
}
public UserManager getUserManager() {
return userManager;
}
@Resource
public void setUserManager(UserManager userManager) {
this.userManager = userManager;
}
}