ユーザーが子犬情報を入力するための jsp が 1 つあります。
<FORM action="/publish" method="post" commandName="puppy" >
<table border=0 cellspacing=0 cellpadding="0">
<% String[] textFields = {"category", "name", "gender", "age", "price"};
for (int j= 0; j<textFields.length; j++){ %>
<tr> <td> <%=textFields[j]%>: </td>
<td> <input type=text name=<%=textFields[j]%>> </td>
</tr>
<% } %>
</table>
<input type = "submit" value="submit">
</FORM>
カテゴリ、名前、性別、年齢、価格を含む子犬オブジェクトがあります。
コントローラーで、ユーザーが書いた子犬の情報を取得したい
@RequestMapping(value = "/publish")
public String publish (@ModelAttribute("puppy") Puppy newP, BindingResult result){
System.out.println("Puppyname: " + newP.getName());
return "redirect:publish.jsp";
}
これは機能しません。助けてくれてありがとう!