「Spring」@ModelAttributeとRequestMethod.POSTのサンプル

構文
JSP画面
<form:form action="abcForm" method="post" modelAttribute="abcForm">
Controller側
public String 関数名(@ModelAttribute xxxForm abcForm,Model model )

1.JSP側

<form:form action="userForm" method="post" modelAttribute="userForm">
 <form:hidden path-"userId"/>
  <form:input path="userMemo"></form:input>
 </form:form>

2.Controller側

@RequestMapping(value ='/create',method = RequestMethod.POST)
public String getProfile(@ModelAttribute UserForm userForm,Model model ) {
   model.addAttribute("profileId", "123"+userForm.getUserId() );
   model.addAttribute("profileMemo", "testmark"+userForm.getUserMemo()) 
   // some code
}

3.Form側

public class UserForm {
    private String userId;
    private String userMemo;
       //some code
}

 

SpringMVC

Posted by arkgame