Result.java:
HashMap
result.jsp(带表单的片段)
public class Result {
private Float weight;
private Float series;
private Float rep;
private String doneDate;
public Float getWeight() {
return weight;
}
public void setWeight(Float weight) {
this.weight = weight;
}
public Float getSeries() {
return series;
}
public void setSeries(Float series) {
this.series = series;
}
public Float getRep() {
return rep;
}
public void setRep(Float re) {
this.rep = rep;
}
public String getDoneDate() {
return doneDate;
}
public void setDoneDate(String doneDate) {
this.doneDate = doneDate;
}
}
和<form:form method="POST" modelAttribute="resultForm" class="form-signin" action="/main/result/${object.id}">
<spring:bind path="weight">
<div class="form-group ${status.error ? 'has-error' : ''}" style="display: inline;">
<form:input style="width:30%" type="text" path="weight" class="form-control resultsave"></form:input>
</div>
</spring:bind>/
<spring:bind path="series">
<div class="form-group ${status.error ? 'has-error' : ''}" style="display: inline;">
<form:input style="width:30%" type="text" path="series" class="form-control resultsave" ></form:input>
</div>
</spring:bind>/
<spring:bind path="rep">
<div class="form-group ${status.error ? 'has-error' : ''}" style="display: inline;">
<form:input style="width:30%" type="text" path="rep" class="form-control resultsave" ></form:input>
</div>
</spring:bind>
<br/>
<spring:bind path="doneDate">
<div class="form-group ${status.error ? 'has-error' : ''}" style="display:inline">
<form:input type="text" id="datepicker" path="doneDate" class="form-control resultsave" value="${date}"></form:input>
</div>
</spring:bind>
<br />
<button class="btn btn-lg btn-primary btn-block overlayLink button big alt" type="submit">Zapisz wyniki</button>
</form:form>
方法的控制器
POST
验证者(我已经发表评论,因为我不确定是什么导致了我的问题):
@RequestMapping(value = "/main/result/{id}", method = RequestMethod.POST)
public String save(@ModelAttribute("resultForm") Result result, @PathVariable("id") Long id, BindingResult bindingResult, Model model,Principal principal){
Exercise exercise = exerciseService.findById(id);
if(exercise.getUsername().equals(principal.getName())){
resultValidator.validate(result, bindingResult);
return "redirect:main";
}
else
return "redirect:main";
}
然而,每当我提交表格时,我都会收到不好的请求,有人能指出我做错了吗?
13:46:5533警告 [org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver] (默认任务-62)无法绑定请求元素: org.springframework.web.method.annotation.MethodArgumentTypeMismatchException: 无法将[java.lang.String]类型的值转换为所需类型 [java.lang.Long中];嵌套异常是java.lang.NumberFormatException: 对于输入字符串:&#34; main&#34;
答案 0 :(得分:-1)
所传递的id的值应为数字(长整数),但是您在击中(/main/result/${object.id}
)时传递了字符串值,该值无法转换为数字。请共享完整的jsp页面。