这是我的updateUser控制器方法
@RequestMapping(value = {"/edit-user-{id}"}, method = RequestMethod.POST)
public String updateUser(@Valid User userForm, BindingResult bindingResult, ModelMap model, @PathVariable Long id) {
model.addAttribute("edit", true);
model.addAttribute("success", "User " + userForm.getFirstName() + " " + userForm.getLastName() + " updated successfully");
userValidator.validate(userForm, bindingResult);
if (bindingResult.hasErrors()) {
return "forward:/registration";
}
userService.updateUser(userForm);
model.addAttribute("userForm", userForm);
return "registrationSuccess";
}
这是我的addDocuments方法
@RequestMapping(value = {"/add-document-{id}"}, method = RequestMethod.GET)
public String addDocuments(@PathVariable Long id, ModelMap model) {
User user = userService.findById(id);
try {
if (user.getUsername() != null && !user.getUsername().equals(context.getUserPrincipal().getName())) {
return "login";
}
} catch (Exception ex) {
throw new DocumentNotFoundException("No document found with that id or userName");
}
model.addAttribute("user", user);
FileBucket fileModel = new FileBucket();
model.addAttribute("fileBucket", fileModel);
List<Catalog> documents = catalogService.findAllByUserId(id);
model.addAttribute("documents", documents);
return "manageDocuments";
}
当updateUser方法中存在绑定结果错误时,它会进入&#34; registration.jsp&#34;
当我按下添加文档按钮时,它会抛出这种异常
nested exception is java.lang.IllegalArgumentException: id to load is required for loading.
这是注册jsp
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<c:set var="contextPath" value="${pageContext.request.contextPath}"/>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="comment" content="">
<meta name="author" content="">
<title>Create an account</title>
<link href="${contextPath}/resources/css/bootstrap.min.css" rel="stylesheet">
<link href="${contextPath}/resources/css/common.css" rel="stylesheet">
<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
</head>
<body>
<div class="container">
<form id="logoutForm" method="POST" action="${contextPath}/logout">
<input type="hidden" name="${_csrf.parameterName}" value="${_csrf.token}"/>
</form>
<form:form method="POST" modelAttribute="userForm" class="form-signin">
<c:choose>
<c:when test="${edit}">
<h2 class="form-signin-heading"><spring:message code= "account.edit.label"/></h2>
</c:when>
<c:otherwise>
<h2 class="form-signin-heading"><spring:message code= "account.create.label"/></h2>
</c:otherwise>
</c:choose>
<c:if test="${!edit}">
<spring:bind path="username">
<div class="form-group ${status.error ? 'has-error' : ''}">
<form:input type="text" path="username" class="form-control" placeholder="Username"
autofocus="true"></form:input>
<form:errors path="username"></form:errors>
</div>
</spring:bind>
</c:if>
<spring:bind path="firstName">
<div class="form-group ${status.error ? 'has-error' : ''}">
<form:input type="text" path="firstName" class="form-control" placeholder="First name"
autofocus="true"></form:input>
<form:errors path="firstName"></form:errors>
</div>
</spring:bind>
<spring:bind path="lastName">
<div class="form-group ${status.error ? 'has-error' : ''}">
<form:input type="text" path="lastName" class="form-control" placeholder="Last name"
autofocus="true"></form:input>
<form:errors path="lastName"></form:errors>
</div>
</spring:bind>
<spring:bind path="email">
<div class="form-group ${status.error ? 'has-error' : ''}">
<form:input type="text" path="email" class="form-control" placeholder="Email"
autofocus="true"></form:input>
<form:errors path="email"></form:errors>
</div>
</spring:bind>
<spring:bind path="skypeID">
<div class="form-group ${status.error ? 'has-error' : ''}">
<form:input type="text" path="skypeID" class="form-control" placeholder="Skype ID"
autofocus="true"></form:input>
<form:errors path="skypeID"></form:errors>
</div>
</spring:bind>
<spring:bind path="password">
<div class="form-group ${status.error ? 'has-error' : ''}">
<form:input type="password" path="password" class="form-control" placeholder="Password"></form:input>
<form:errors path="password"></form:errors>
</div>
</spring:bind>
<spring:bind path="passwordConfirm">
<div class="form-group ${status.error ? 'has-error' : ''}">
<form:input type="password" path="passwordConfirm" class="form-control"
placeholder="Confirm your password"></form:input>
<form:errors path="passwordConfirm"></form:errors>
</div>
</spring:bind>
<c:if test="${edit}">
<span class="well pull-left">
<a href="<c:url value='/add-document-${userForm.id}' />" class="btn btn-primary btn-sm"><spring:message code= "button.upload.text"/></a>
</span>
</c:if>
<button class="btn btn-lg btn-primary btn-block" type="submit"><spring:message code= "button.submit.label"/></button>
<h3><a onclick="document.forms['logoutForm'].submit()"><spring:message code= "button.logout.label"/></a></h3>
</form:form>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script src="${contextPath}/resources/js/bootstrap.min.js"></script>
</body>
</html>
请帮我找出如何重定向或转发。