09920171007 09920171007 //结论:当实体类较多的时候,采用模型驱动。不管在哪里写,private属性都给它设上set[注入数据]和get方法[获取数据] 1 、属性驱动 public class UserAction extends ActionSuppo
09920171007
//结论:当实体类较多的时候,采用模型驱动。不管在哪里写,private属性都给它设上set[注入数据]和get方法[获取数据]
1、属性驱动
public class UserAction extends ActionSupport{
private String name;
public String login(){
System.out.println(name);
return Action.SUCCESS;
}
public User getName() {
return name;
}
public void setUser(String name) {
this.name = name;
}
}
2、模型驱动[最常用][前台传递参数形式(...?user.name = tiger&user.age = 22)]
public class ActionSupport {
private User user;
public String login() {
System.out.println("UserDomain.add()");
System.out.println("User.name=" + user.getName());
System.out.println("User.age=" + user.getAge());
return SUCCESS;
}
public User getUser() {
return user;
}
public void setUser(User user) {
this.user = user;
}
}
3、模型驱动[不常用]
public class UserModelAction extends ActionSupport implements ModelDriven
{
private User user = new User();
public String login(){
System.err.println(user);
return Action.SUCCESS;
}
@Override
public User getModel() {
return user;
}
}