spring mvcを学習しようとしています。 @ModelAttributeがどのように動作するかを理解することができません。私は学生オブジェクトを作成し、学生形式のページに移動し、属性名「テスト名」でモデルに追加すると、以下の私のコントローラ@ModelAttribute( "")annotationはまだspring mvcの間違ったパラメータで動作しています
@RequestMapping("/showForm")
public String showForm(Model theModel){
Student student = new Student();
theModel.addAttribute("testName",student);
return "student-form";
}
@RequestMapping("/processForm")
public String showForm(@ModelAttribute("hello") Student student){
return "student-confirmation";
}
です。それから私は "processForm"メソッドにフォームに送信します。ここでは、フォーム
<form:form action="processForm" modelAttribute="testName">
First Name: <form:input path="firstName" />
Second Name: <form:input path="lastName" />
<input type="submit" value="submit" />
</form:form>
の下に使用すると、私は属性名は、私がモデル化するためにオブジェクトを置く場所で、どこで、私はそれをretriveと一致していない理解し `tをするものです。しかし、その結果は...正しく表示され
theModel.addAttribute("testName",student); //Here it is testName
@ModelAttribute("hello") Student student //Here it is hello
学生モデルはあなたがモデル属性としてテスト名を設定しているので、後にフォームを送信自動的に入力され