我在一个 jsp 页面上有两个表单。第一种形式不使用modelAttribute,而第二种形式使用modelAttribute。问题是,如果我发布第一个不使用 modelAttribute 的表单,则会声明我没有绑定 modelAttribute 的错误。
我已经在互联网上搜索以寻找解决方案,但我找不到有用的解决方案。
更改地址.jsp
<form method="post">
<input type="hidden" name="id" value="0" />
<input type="submit" name="exist" value="send to this address" />
</form>
<form:form method="post" modelAttribute="addressForm">
<form:input path="street" />
<input type="submit" name="add" value="send to this address" />
</form:form>
订单控制器.java
@RequestMapping(value="changeAddress",method = RequestMethod.GET)
public ModelAndView showChangAddress(Model model)
{
model.addAttribute("addressForm", new AddressForm());
return new ModelAndView("body.changeaddress");
}
@RequestMapping(value="changeAddress", params="add", method = RequestMethod.POST)
public ModelAndView addChangAddress(@ModelAttribute("addressForm") @Valid AddressForm af, BindingResult result, Model model)
{
System.out.println("a");
return new ModelAndView("body.changeaddress");
}
@RequestMapping(value="changeAddress", params="exist", method = RequestMethod.POST)
public ModelAndView processChangAddress(@RequestParam(value="id") String id, Model model)
{
System.out.println("b");
return new ModelAndView("body.changeaddress");
}
非常感谢帮助:)