@ResponseBody
@RequestMapping("/model-attribute-v2")
public String requestModelV2(@ModelAttribute HelloData helloData)
{
log.info("username={}",helloData.getUsername());
log.info("age = {}",helloData.getAge());
return "ok";
}
스프링은 @ModelAttribute가 있으면 다음 프로세스대로 실행된다.
1] HelloData 객체 생성
2] Request 매개변수의 이름으로 HelloData 객체의 멤버 변수를 찾는다.
3] 해당 멤버 변수의 Setter를 호출하여 Request 매개변수를 바인딩한다.
-> 반드시 HelloData 클래스에는 setter가 정의돼 있어야 한다.
ex) Request 매개변수 이름이 username인 경우 HelloData객체.setUsername()이 호출
'Springあるある' 카테고리의 다른 글
static class에 @Component 사용 시 주의점! (0) | 2025.01.06 |
---|---|
Request Body 전체 조회!!(Feat. HttpEntity) (0) | 2025.01.03 |
@RequestParam(required=true)의 주의점 (0) | 2025.01.03 |
@ResponseBody(Feat. produces) (0) | 2025.01.03 |
스프링 로그(feat. SLF4J ,Logback) (1) | 2025.01.03 |