@ModelAttribute와 Model

2025. 4. 4. 19:23·📁 Spring/Lecture

@ModelAttribute

HTTP 요청 파라미터를 바인딩해서 객체에 주입 + 뷰에 모델 데이터를 전달

바인딩된 객체를 Model에 자동으로 등록

 

 

Model

뷰에 전달할 데이터를 저장하는 컨테이너

model.addAttribute("name", value)로 뷰로 값 전달

@PostMapping("/register")
public String register(@ModelAttribute User user, Model model) {
  model.addAttribute("message", "등록 성공!");
  return "registerResult";
}

@ModelAttribute: 요청 파라미터 → User 객체 바인딩 + model.addAttribute("user", user) 자동

Model: 추가로 다른 값 전달 가능

반응형

'📁 Spring > Lecture' 카테고리의 다른 글

빈 스코프  (0) 2025.03.25
스프링의 빈 생명주기 콜백 지원  (2) 2025.03.24
Annotation 직접 생성  (0) 2025.03.24
조회 빈이 2개 이상일 때  (0) 2025.03.24
의존관계 주입  (0) 2025.03.24
'📁 Spring/Lecture' 카테고리의 다른 글
  • 빈 스코프
  • 스프링의 빈 생명주기 콜백 지원
  • Annotation 직접 생성
  • 조회 빈이 2개 이상일 때
leee
leee
  • leee
    LEE
    leee
  • 전체
    오늘
    어제
    • 카테고리
      • 📁 QA
        • Test
        • Lecture
      • 📁 SQL
        • 📝
      • 📁 Spring
        • Lecture
        • Error
      • 📁 Github
  • 블로그 메뉴

    • 🏠
  • 링크

  • 공지사항

  • 인기 글

  • 태그

    AppConfig
    SQL_Join
    생성자주입
    shift_연산자
    mismatch
    COUNT(*)
    DI 컨테이너
    MySQL
    API 자동화 테스트
    Postman
    api 테스트
    깃허브 인텔리제이 연동 해제
    API test
    mysql_join
    API Testing
    mysql_기간_검색
    스프링 객체지향
    포스트맨
    mysql_연산자
    mysql_데이터타입변환
  • 최근 댓글

  • 최근 글

  • hELLO· Designed By정상우.v4.10.5
leee
@ModelAttribute와 Model
상단으로

티스토리툴바