3

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");
}

助けてくれてありがとう:)

4

1 に答える 1

3

タグに関するスプリング フォーム taglibドキュメント<form>:

このタグは、HTML の「フォーム」タグをレンダリングし、バインディング用の内部タグへのバインディング パスを公開します。コマンド オブジェクトを PageContext に配置して、内部タグからコマンド オブジェクトにアクセスできるようにします。

<form>最初のフォームの spring タグからは何も必要ないと思います。したがって、代わりに単純な html フォームを使用できます。

<form method="post" action="...">
     <input type="hidden" name="id" value="0" />
     <input type="submit" name="exist" value="send to this address" />
<form>
于 2013-01-03T11:01:35.317 に答える