我已经创建了一个提交表单,并编写了一个控制器方法来处理它在Spring MVC中。但请求没有达到控制器方法。请让我知道我在编写控制器/表单方法时犯了什么错误。 下面是我的代码片段,它是自我解释的。
控制器方法:
@RequestMapping(value="/users/login/projectUpdate",method=RequestMethod.POST)
public String updateProjectStatus( User user,Model model,Authentication
authentication,HttpServletRequest request,final RedirectAttributes
redirectAttributes) {
logger.debug("Update Project Status Data()");
String projectname=request.getParameter("projectName");
String projectStatus=request.getParameter("projectStatus");
String projectStatusDate=request.getParameter("projectStatusDate");
userService.updateProject(projectStatus,projectStatusDate,projectname);
return "users/updateProject";
}
JSP表单:
<spring:url value="/users/login/projectUpdate" var="updateProjectUrl" />
<form:form method="post" modelAttribute="updateProjectForm"
action="${updateProjectUrl}" id="ProjectForm">
<label class="col-sm-2 control-label">Projects</label>
<div class="col-sm-9">
<form:select path="project" multiple="false" class="form-control" id="project1">
<form:option label="--Select--" value=""/>
<form:options items="${project}" />
</form:select>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">Project Description</label>
<div class="col-sm-9">
<form:input path="projectDescription" type="text" class="form-control" id="projectDescription1" placeholder="Project Description" readonly="true"/>
</div>
</div>
<div class="form-group ${status.error ? 'has-error' : ''}">
<label class="col-sm-2 control-label">Project Start Date</label>
<div class="col-sm-9">
<form:input path="projectStartDate" type="text" class="form-control" id="projectStartDate1" placeholder="Project Start Date" readonly="true" />
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">Current Status</label>
<div class="col-sm-9">
<form:input path="projectCurrentStatus" type="text" class="form-control" id="projectCurrentStatus" placeholder="Project Status" readonly="true"/>
</div>
</div>
<div class="form-group ${status.error ? 'has-error' : ''}">
<label class="col-sm-2 control-label">Current Status Date</label>
<div class="col-sm-9">
<form:input path="projectCurrentStatusDate" type="text" class="form-control " id="projectCurrentStatusDate" placeholder="Project Current Status Date" readonly="true"/>
</div>
</div>
<label class="col-sm-2 control-label">New Status</label>
<div class="col-sm-9">
<form:select path="projectStatus" multiple="false" class="form-control" id="projectStatus1" >
<form:option label="--Select--" value=""/>
<form:options items="${projectstatus}" />
</form:select>
</div>
<label class="col-sm-2 control-label">New Status Date</label>
<div class="col-sm-9">
<form:input path="projectStatusDate" type="date" class="form-control " id="projectStatusDate1" placeholder="Project Status Date" data-validation="date" data-validation-format="yyyy-mm-dd" />
</div>
<div class="form-group">
<label class="col-sm-2 control-label">Project Team Members</label>
<div class="col-sm-9">
<form:input path="projectTeam" type="text" class="form-control " id="projectTeam1" placeholder="Project Team members" />
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-5 col-sm-7">
<button type="submit" class="btn btn-success">Update</button>
</div>
</div>
答案 0 :(得分:0)
请尝试使用如下的BindingResult:
public String updateProjectStatus( User user,BindingResult bindingResult,Model model,Authentication authentication,HttpServletRequest request,final RedirectAttributes redirectAttributes){
if (bindingResult.hasErrors()) {
//check your errors here
}
}
并确保您从JSP传递的所有字段都应出现在User类中。