hanker

@ModelAttribute 어노테이션 본문

SPRING

@ModelAttribute 어노테이션

hanker 2022. 6. 7. 11:45

@ModelAttribute 어노테이션

 

여러가지 코드를 보면 컨트롤러에서 파라미터를 받는 부분에 @ModelAttribute 어노테이션이 붙어 있는걸 볼 수 있다.

 

이 어노테이션을 사용하면 VO, DTO 클래스에 정의된 값을 파라미터로 받을 수 있는데, 이는 view page에서 폼데이터를 가져올 때 많이 사용한다.

 

또한 생략도 가능하다.

@RequestMapping(value = "/actionLogin.do")
public String actionLogin(@ModelAttribute("loginVO") LoginVO loginVO, HttpServletRequest request, ModelMap model) throws Exception {


}
@RequestMapping(value = "/actionLogin.do")
public String actionLogin(LoginVO loginVO, HttpServletRequest request, ModelMap model) throws Exception {

}

위 코드와 아래코드의 받아오는 값은 같다.