스프링 부트, 입문!

스프링 부트, 입문!

쉽고 빠르게 배우는, 스프링 부트 첫걸음!

05 MVC의 역할과 실행 흐름

# MVC의 역할과 실행 흐름 ## 미션 다음 URL요청에 대한 응답 페이지를 만드시오. ![홍팍-스프링-부트-입문-MVC-미션](http://drive.google.com/thumbnail?export=view&sz=w960&id=1dmEu_TfcXSSk28JGSjksh5vt38fCWDGt) ## 01:36 리뷰 - 요청에서 응답까지 #### ../controller/FirstController ``` package com.example.firstproject.controller; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.GetMapping; @Controller public class FirstController { @GetMapping("/hi") public String niceToMeetYou(Model model) { model.addAttribute("username", "hongpark"); return "greetings"; } } ``` #### ../templates/greetings.mustache ``` <html> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Document</title> </head> <body> <h1>{{username}}님, 반갑습니다.</h1> </body> </html> ``` ## 04:57 응용 - 또 다른 요청에 응답하기 #### ../controller/FirstController ``` package com.example.firstproject.controller; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.GetMapping; @Controller public class FirstController { @GetMapping("/hi") public String niceToMeetYou(Model model) { model.addAttribute("username", "hongpark"); return "greetings"; } @GetMapping("/bye") public String seeYouNext(Model model) { model.addAttribute("nickname", "홍길동"); return "goodbye"; } } ``` #### ../templates/goodbye.mustache ``` <html> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Document</title> </head> <body> <h1>{{nickname}}님, 다음에 또 만나요!</h1> </body> </html> ``` ## 🔥 구글링 훈련하기 - 웹서버 요청 응답 과정 - MVC 패턴 장점