Bean:
public class User {
private String name;
private String password;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
}
Controller代码:
@RequestMapping("addUser")
public String addUser(User user){
userServiceImp.addUser(user);
System.out.println("---------------------------------");
return "success";
}
表单代码:
<p>添加用户</p>
<form action="addUser.do" method="post">
userName:<input type="text" name="name"/><br/>
password:<input type="text" name="password">
<input type="submit"/>
</form>
只需将对象的属性名和input的name值匹配即可。