我在一个jsp页面上有两种形式.第一种形式不使用modelAttribute,第二种形式使用modelAttribute.问题是,如果我发布不使用modelAttribute的第一个表单,则会声明我没有绑定modelAttribute的错误.
changeAddress.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>
OrderController.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");
}
恳求帮助:)
最佳答案
关于< form>的spring形式标签库documentation .标签:
This tag renders an HTML ‘form’ tag and exposes a binding path to inner tags for binding. It puts the command object in the PageContext so that the command object can be accessed by inner tags.
我认为您从Spring< form>起就不需要任何东西了.以您的第一种形式标记.因此,您可以使用简单的html表单代替:
<form method="post" action="...">
<input type="hidden" name="id" value="0" />
<input type="submit" name="exist" value="send to this address" />
<form>