如果我有如下的 Spring 表单:
<c:url value="/user/profile?id=${user.id}" var="profileURL" />
<form:form action="${profileURL}" method = "get">
<input type="submit" value="My profile">
</form:form>
春天抱怨说:
Your page request has caused a MissingServletRequestParameterException: Required String parameter 'id' is not present error:
但是,在控制器方法中,存在参数:
@RequestMapping(value = "/profile", method = RequestMethod.GET)
public String getProfile(@RequestParam("id") String id, Model model) {
User user = userService.get(Integer.parseInt(id));
model.addAttribute("user", user);
return "profile";
}
谁能告诉这是为什么?
如果我使用一个简单的表单字段,例如:
<input name="id" type="hidden" value="=${user.id}">
万事皆安。但我更喜欢使用 Spring 字段,隐藏的必要。
在运行时,表单如下所示:
<form id="command" action="/nameOfapplication/user/profile?id=3" method="get">
<input type="submit" value="My profile">
</form>
这会导致堆栈跟踪中出现以下消息:
您的页面请求导致 MissingServletRequestParameterException: Required String parameter 'id' is not present 错误:
org.springframework.web.method.annotation.RequestParamMethodArgumentResolver.handleMissingValue(RequestParamMethodArgumentResolver.java:255)