【Struts2复习知识点八】-DomaimModel域模型接收参数

 DomaimModel域模型  就是将参数封装成 dto 对象。

struts.xml

View Code
<struts>
<constant name="struts.devMode" value="true" />
<package name="user" extends="struts-default" namespace="/user">

<action name="user" class="com.bjsxt.struts2.user.action.UserAction">
<result>/user_add_success.jsp</result>
</action>
</package>
</struts>

User.java

View Code
public class User {
private String name;
private int age;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
}

 UserAction.java

View Code
public class UserAction extends ActionSupport {

private User user;

// private UserDTO userDTO;
public String add() {
System.out.println("name=" + user.getName());
System.out.println("age=" + user.getAge());
return SUCCESS;
}

public User getUser() {
return user;
}

public void setUser(User user) {
this.user = user;
}

}


访问:http://localhost:8080/project/user/user!add?user.name=a&user.age=8

DO :data object

VO  :view object

DTO: data transfer object

posted @ 2012-02-22 11:29  濤叔  阅读(496)  评论(0编辑  收藏  举报