日期:2014-05-19 浏览次数:20680 次
<form action="user/update" method="post"> <table border="0" align="center" width="700"> <tr height="30"><td colspan="2"><s:debug/></td></tr> <tr height="30"><td colspan="2"><s:fielderror/></td></tr> <tr height="30"><td>姓:</td><td><input type="text" name="firstname" value="${firstname}"></td></tr> <tr height="30"><td>名:</td><td><input type="text" name="secondname" value="${secondname}"></td></tr> <tr height="30"><td>年龄</td><td><input type="text" name="age" value="${age}"></td></tr> <tr height="30"><td colspan="2"><input type="submit" value="submit"> <input type="reset" value="reset"></td></tr> </table> </form>
import javax.annotation.Resource; import org.springframework.context.annotation.Scope; import org.springframework.stereotype.Controller; import com.hktk.entity.user.User; import com.hktk.service.user.UserService; import com.opensymphony.xwork2.ActionSupport; import com.opensymphony.xwork2.ModelDriven; @Controller("updateUserAction") @Scope("prototype") public class UpdateUserAction extends ActionSupport implements ModelDriven<User>{ private static final long serialVersionUID = 1L; private User user = new User(); private UserService userService; @Resource public void setUserService(UserService userService) { this.userService = userService; } public User getUser() { return user; } public void setUser(User user) { this.user = user; } public String update() { user = userService.load(user.getId()); System.out.println(user); return INPUT; } @Override public User getModel() { return getUser(); } }
import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.Id; import javax.persistence.Table; @Entity @Table(name="t_user") public class User { private Integer id; private String firstname; private String secondname; private int age; @Id @GeneratedValue public Integer getId() { return id; } public void setId(Integer id) { this.id = id; } public String getFirstname() { return firstname; } public void setFirstname(String firstname) { this.firstname = firstname; } public String getSecondname() { return secondname; } public void setSecondname(String secondname) { this.secondname = secondname; } public int getAge() { return age; } public void setAge(int age) { this.age = age; } }
public class UserInfo { private Integer id; private String firstname; priv