当我尝试提交(Spring)表单查询时:
我没有收到消息。
控制器
@RequestMapping(value = "beerbean", method = RequestMethod.GET)
public String showForm(@ModelAttribute("beerbean") BeerBean beerbean){
return "addbeerform";
}
@RequestMapping(value = "beerbean", method = RequestMethod.POST)
public String newBeer(Model model, @Valid @ModelAttribute BeerBean beerbean,
BindingResult bindingResult){
if(bindingResult.hasErrors()){
return "addbeerform";
}
model.addAttribute("beani", beerbean);
return "showBeer";
}
addbeerform.jsp
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<form:form commandName="beerbean" action="${pageContext.request.contextPath}/app
/beerbean" method="POST">
<form:input path="name" /><form:errors path="name" /><br/>
<form:input path="id" /><form:errors path="id" /><br/>
<input type="submit">
</form:form>
当字段中没有错误时,它会工作并转到&#34; showBeer&#34;,但是当它出现故障时就会崩溃。我也有实现Serializable等的BeerBean类,但是不认为解决方案在那里(变量有类似参数的形式,输入路径=&#34;名称&#34;转到私有String名称等)
答案 0 :(得分:0)
我建议明确指定模型属性的名称:
public String newBeer(
Model model,
@Valid @ModelAttribute("beerbean") BeerBean beerbean,
BindingResult bindingResult
) {