我是新来的Spring。我正在尝试创建editUser. jsp以在mysql数据库中编辑用户。出于这个原因,我创建了用于将数据从userList.jsp表单传递到editUser.jsp的控制器和方法。这是代码:
@RequestMapping(value = "/editUser", method = RequestMethod.POST)
private String editUser(@RequestParam int id, Model model) {
Users user = (Users) session.load(Users.class, id);
ModelAndView mv = new ModelAndView("user");
model.addAttribute("user", user);
if(user.getId()!=null){
Transaction transaction = session.beginTransaction();
session.update(user);
transaction.commit();
}
return "editUser";
}
并且数据很好地传递给editUser页面。现在,当我尝试编辑和提交数据时,我收到了错误消息:不存在必需的int参数'id'
<form:form action="editUser.htm" method="GET" commandName="editUser">
<div>Account Information</div>
<div>
<form:label path="uname">User name:</form:label><br/>
<form:input id="uname" type="text" path="uname"></form:input><br/>
<form:label path="pass">Password:</form:label><br/>
<form:input id="pass" type="text" path="pass"></form:input><br/>
</div>
<br/><br/>
<div>Contact Information</div>
<div>
<form:label path="gender">Choose gender:</form:label><br/>
<form:select id="gender" type="text" path="gender">
<form:option value="Female">Female</form:option>
<form:option selected="selected" value="Male">Male</form:option>
</form:select><br/>
<form:label path="age">Age:</form:label><br/>
<form:input id="age" type="text" path="age"></form:input><br/>
<form:label path="age">Address:</form:label><br/>
<form:input id="address" type="text" path="address"></form:input><br/>
</div>
<input type="submit" value="Edit User"/>
</form:form>enter code here
我是否需要在控制器中创建另一个方法来处理数据库中的更新数据或更新处理可以在现有方法中完成(目前,我完全不明白jsp页面如何知道将调用Controller中的哪个方法)?数据库列id已设置-自动增量。
提前感谢。
@Request estParam(值="id",必填="false")int id