[항해99] MVC(Model - View - Controller) 내용정리

정선모·2022년 1월 29일
0

CS

목록 보기
2/8

스프링 MVC란 ? - MVC (Model - View - Controller) 디자인 패턴을 말합니다.

서버에서 HTML을 내려주는 경우

  1. 정적 (static) 웹 페이지
    -Controller
  • Client 의 요청을 Model 로 받아 처리
    - 예) 회원가입을 위한 개인 정보들 (id, password, name)
  • Client 에게 View (정적 웹 페이지, HTML) 를 내려줌
  1. 동적 (dynamic) 웹 페이지
    -Controller
  • Client 의 요청을 Model 로 받아 처리
  • Template engine(Thymeleaf 등) 에게 View, Model 전달
    • View: 동적 HTML 파일
    • Model: View 에 적용할 정보들
  • Template engine
    - View 에 Model 을 적용 → 동적 웹페이지 생성
    • 예) 로그인 성공 시, "로그인된 사용자의 id" 를 페이지에 추가
    • 예) 예) 로그인 성공 시, "로그인된 사용자의 id" 를 페이지에 추가
  • Client 에게 View (동적 웹 페이지, HTML) 를 내려줌

HTTP 메시지 이해

  • Client 와 Server 간 Request, Response 는 HTTP 메시지 규약을 따름
  • HTTP 메시지는 웹 서비스 개발자(백엔드, 프론트 개발자)에게 매우 중요한 내용!!

-메시지 구조

1. 시작줄 (start line)
-Response 에선 '상태줄 (status line)' 이라고 부름
2. 헤더 (headers)
3. 본문 (body)

-Request 메시지
1. 시작줄: API 요청 내용
2. 헤더

  • "Content type"
    - 없음.
    - HTML form 태그로 요청 시
Content type: application/x-www-form-urlencoded

      - AJAX 요청

Content type: application/json

3. 본문

  • GET 요청 시: (보통) 없음
  • POST 요청 시: (보통) 사용자가 입력한 폼 데이터

-Response 메시지
1. 상태줄: API 요청 결과 (상태 코드, 상태 텍스트)
2. 헤더

  • "Contetn type"
    1. 없음.
    2. Response 본문 내용이 HTML 인 경우
Content type: text/html

      3. Response 본문 내용이 JSON 인 경우

Content type: application/json
  • "Location"
    - Redirect 할 페이지 URL
Location: http://localhost:8080/hello.html
  1. 본문
    • HTML
<!DOCTYPE html>
<html>
  <head><title>By @ResponseBody</title></head>
   <body>Hello, Spring 정적 웹 페이지!!</body>
</html>
- JSON
{ 
  "name":"홍길동",
  "age": 20
}

Controller 와 HTTP Response 메시지

Controller 와 HTTP Request 메시지

스프링 MVC 동작원리

profile
개발자가 되어가는 비전공자

0개의 댓글