[Spring Boot]@ModelAttributeアノテーションのサンプル

2021年4月7日

1.Controller側クラスの作成

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
@ModelAttribute
UserForm setUpForm(){
return new UserForm();
}
@RequestMapping(value ="/",method =RequestMethod.GET)
public ModelAndView index(ModelAndView ma) {
ma.setViewName("index");
ma.addObject("userLst",new UserForm());
return ma;
}
@ModelAttribute UserForm setUpForm(){ return new UserForm(); } @RequestMapping(value ="/",method =RequestMethod.GET) public ModelAndView index(ModelAndView ma) { ma.setViewName("index"); ma.addObject("userLst",new UserForm()); return ma; }
@ModelAttribute
UserForm setUpForm(){
  return new UserForm();
}

@RequestMapping(value ="/",method =RequestMethod.GET)
public ModelAndView index(ModelAndView ma) {
 
   ma.setViewName("index");
   ma.addObject("userLst",new UserForm());
   return ma;
}

2.テンプレートファイル
<form method="post" action="/User/find" th:object="${userList}">

Spring Boot

Posted by arkgame