-
Notifications
You must be signed in to change notification settings - Fork 170
[Spring MVC] 강동현 미션제출합니다 #512
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: mintcoke123
Are you sure you want to change the base?
Changes from 6 commits
a26d3bd
33475a6
2759859
c32009e
7489cf5
7543356
565d8f2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 줄내림 마지막 부분에 없는데 확인 부탁드려요
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 수정했습니다! |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| package roomescape; | ||
|
|
||
| import org.springframework.stereotype.Controller; | ||
| import org.springframework.web.bind.annotation.GetMapping; | ||
|
|
||
| @Controller | ||
| public class HomeController { | ||
| @GetMapping("/") | ||
| public String home() { | ||
| return "home"; | ||
| } | ||
| } |
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 여기도 확인 부탁드릴게요!
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 수정했습니다! |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| package roomescape; | ||
|
|
||
| public record Reservation(int id, String name, String date, String time) { } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| package roomescape; | ||
|
|
||
| import org.springframework.stereotype.Controller; | ||
| import org.springframework.web.bind.annotation.GetMapping; | ||
| import org.springframework.web.bind.annotation.ResponseBody; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
|
|
||
| @Controller | ||
| public class ReservationController { | ||
|
|
||
| private final List<Reservation> reservations = new ArrayList<>(); | ||
|
|
||
| public ReservationController() { | ||
| reservations.add(new Reservation(1, "브라운", "2023-01-01", "10:00")); | ||
| reservations.add(new Reservation(2, "브라운", "2023-01-02", "11:00")); | ||
| reservations.add(new Reservation(3, "브라운", "2023-01-03", "12:00")); | ||
| } | ||
|
|
||
| @GetMapping("/reservation") | ||
| public String reservationPage() { | ||
| return "reservation"; | ||
| } | ||
|
|
||
| @GetMapping("/reservations") | ||
| @ResponseBody | ||
| public List<Reservation> findAll() { | ||
| return reservations; | ||
| } | ||
|
Comment on lines
+21
to
+30
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 컨트롤러를 잘 작성해주셨네요👍👍 컨트롤러 내에서
관련 키워드
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
해당 동작 방식은 다음과 같이 이해했습니다!
GetMapping은 url과 메서드를 연결해주는 역할을 합니다. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 답변을 보면서 제가 중복된 질문을 2번 드렸나 순간 의아했네요 😅 답변 감사합니다! 1, 2, 3번 질문 모두 스프링 MVC의 핵심 동작 원리를 잘 설명해주셨습니다. 특히 2번 답변에서 다만, 1번 답변에서 1번 답변먼저 클라이언트(브라우저)는 클라이언트는 그저 서버에 동현님이 적어주신 부분은, 클라이언트의 3번 답변
|
||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
몇가지 의존성이 있네요!
추가된 의존성은 명확하게 어떤 역할을 하고 있을까요? 간단하게 설명 부탁드릴게요!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
implementation 'org.springframework.boot:spring-boot-starter-web'HTTP 요청/응답을 처리하기 위한 모든 기본 컴포넌트로써,
@GetMapping,@ResponseBody를 사용할 때 사용됩니다!implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'Thymeleaf 템플릿 엔진으로써, ViewResolver(prefix·suffix)를 자동 설정하기 위해 사용됩니다.
위 코드에서 반환되는 String이
.../reservation.html로 랜더링되게 해줍니다.
spring-boot-devtools위 의존성은 코드 수정시에 자동 재시작을 도와줍니다!
템플릿 자동 새로고침을 도와주기 때문에 개발자 편의를 위해 사용됩니다.
사실 devtools를 적용해야 html에 코드 수정사항이 반영되는 걸로 역할을 오해하고 있었는데,
다시 찾아보니 개발 편의성을 위해 이용하는 툴이고 없어도 작동했네요..
그래도 남겨두도록 하겠습니다!