我試圖使用Spring mvc創建更新窗體。一旦用戶點擊更新按鈕,它將顯示輸入標籤中的當前值。當我編輯當前值並點擊提交按鈕時,它顯示以下錯誤。更新窗體錯誤 - Spring4 mvc - org.springframework.beans.TypeMismatchException:
org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver handleTypeMismatch 警告:無法請求元素結合:org.springframework.beans.TypeMismatchException:未能轉換類型的值 'java.lang.String中'到所需的類型'int';嵌套異常是java.lang.NumberFormatException:對於輸入字符串: 「updateStudent」
針對home.jsp
<form:form method="GET" action="updateStudent" commandName="selectedUser">
<table>
<tr>
<form:input path="userID" placeholder="userID"
value="${selectedUsers.userID}" />
<form:input path="userName" placeholder="userName"
value="${selectedUsers.userName}" />
<form:input path="password" placeholder="password"
value="${selectedUsers.password}" />
</tr>
<tr>
<td colspan="2"><input type="submit" value="Submit" /></td>
</tr>
</table>
</form:form>
controller.java
@RequestMapping(value = "updateStudent", method = RequestMethod.GET)
public String updateStudent(@ModelAttribute("selectedUser") User user,
ModelMap model) throws Exception {
Student student = new Student();
System.out.println("come here helloController()");
model.addAttribute("userID", user.getUserID());
model.addAttribute("userName", user.getUserName());
model.addAttribute("password", user.getPassword());
model.addAttribute("student",student);
model.addAttribute("user",user);
System.out.println("student id is " + user.getUserID());
// model.addAttribute("userI", user);
if (user.getUserID() == 0) {
model.addAttribute("error", "please enter id");
return "home";
}
if (user.getUserName() == null) {
model.addAttribute("error", "please enter getUserName");
return "home";
}
if (user.getPassword() == null) {
model.addAttribute("error", "please enter getPassword");
return "home";
}
return "home";
}
User.java
public class User {
int userID;
String userName;
String password;
public int getUserID() {
return userID;
}
public void setUserID(int userID) {
this.userID = userID;
}
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
}
我需要將更新的值傳遞給控制器。希望你有這個問題。請幫忙解決問題。
它沒有工作。它給出了同樣的錯誤:( – dmaprasad
清理並建立你的項目,並再次運行。你的異常說明這是原因。 –
它也沒有工作 – dmaprasad