1 つの jsp ページに 2 つのフォームがあります。最初のフォームは modelAttribute を使用せず、2 番目のフォームは 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");
}
助けてくれてありがとう:)