-
Notifications
You must be signed in to change notification settings - Fork 305
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
[MVC 구현하기 - 3단계] 엔초(권예진) 미션 제출합니다. #575
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
9f56f7b
refactor: 핸들러를 찾을 수 없을 때 404.jsp 를 보여주도록 변경
kwonyj1022 f67d5cc
refactor: 개행 정리 및 불필요한 static 선언 제거
kwonyj1022 f4ce0ae
feat: HandlerExecutor 추가
kwonyj1022 51aeb96
refactor: HandlerMapping과 HanelerAdapter를 DispatcherServletInitialize…
kwonyj1022 a039fd8
feat: UserController 추가
kwonyj1022 bf0005e
feat: JsonView 구현
kwonyj1022 fdad8f7
refactor: 레거시 제거
kwonyj1022 508467a
rename: DispatcherServlet을 mvc 패키지로 이동
kwonyj1022 db7853e
refactor: HandlerExecutor에서 404.jsp를 관리하도록 변경
kwonyj1022 e5ccb8e
feat: model에 데이터가 1개면 값을 그대로 반환하는 기능 추가
kwonyj1022 6e750e4
style: 사용하지 않는 import 제거
kwonyj1022 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 0 additions & 52 deletions
52
app/src/main/java/com/techcourse/ManualHandlerMapping.java
This file was deleted.
Oops, something went wrong.
20 changes: 20 additions & 0 deletions
20
app/src/main/java/com/techcourse/controller/ForwardController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.techcourse.controller; | ||
|
||
import context.org.springframework.stereotype.Controller; | ||
import jakarta.servlet.http.HttpServletRequest; | ||
import jakarta.servlet.http.HttpServletResponse; | ||
import web.org.springframework.web.bind.annotation.RequestMapping; | ||
import web.org.springframework.web.bind.annotation.RequestMethod; | ||
import webmvc.org.springframework.web.servlet.ModelAndView; | ||
import webmvc.org.springframework.web.servlet.view.JspView; | ||
|
||
@Controller | ||
public class ForwardController { | ||
|
||
private static final String PATH = "/index.jsp"; | ||
|
||
@RequestMapping(value = "/", method = RequestMethod.GET) | ||
public ModelAndView execute(final HttpServletRequest request, final HttpServletResponse response) { | ||
return new ModelAndView(new JspView(PATH)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
app/src/main/java/com/techcourse/controller/UserController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package com.techcourse.controller; | ||
|
||
import com.techcourse.domain.User; | ||
import com.techcourse.repository.InMemoryUserRepository; | ||
import context.org.springframework.stereotype.Controller; | ||
import jakarta.servlet.http.HttpServletRequest; | ||
import jakarta.servlet.http.HttpServletResponse; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import web.org.springframework.web.bind.annotation.RequestMapping; | ||
import web.org.springframework.web.bind.annotation.RequestMethod; | ||
import webmvc.org.springframework.web.servlet.ModelAndView; | ||
import webmvc.org.springframework.web.servlet.view.JsonView; | ||
|
||
@Controller | ||
public class UserController { | ||
|
||
private static final Logger log = LoggerFactory.getLogger(UserController.class); | ||
|
||
@RequestMapping(value = "/api/user", method = RequestMethod.GET) | ||
public ModelAndView show(HttpServletRequest request, HttpServletResponse response) { | ||
final String account = request.getParameter("account"); | ||
log.info("user id : {}", account); | ||
|
||
final ModelAndView modelAndView = new ModelAndView(new JsonView()); | ||
final User user = InMemoryUserRepository.findByAccount(account) | ||
.orElseThrow(); | ||
|
||
modelAndView.addObject("user", user); | ||
return modelAndView; | ||
} | ||
} |
38 changes: 0 additions & 38 deletions
38
app/src/main/java/com/techcourse/controller/manual_controller/LoginController.java
This file was deleted.
Oops, something went wrong.
23 changes: 0 additions & 23 deletions
23
app/src/main/java/com/techcourse/controller/manual_controller/LoginViewController.java
This file was deleted.
Oops, something went wrong.
16 changes: 0 additions & 16 deletions
16
app/src/main/java/com/techcourse/controller/manual_controller/LogoutController.java
This file was deleted.
Oops, something went wrong.
21 changes: 0 additions & 21 deletions
21
app/src/main/java/com/techcourse/controller/manual_controller/RegisterController.java
This file was deleted.
Oops, something went wrong.
13 changes: 0 additions & 13 deletions
13
app/src/main/java/com/techcourse/controller/manual_controller/RegisterViewController.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
mvc/src/main/java/webmvc/org/springframework/web/servlet/mvc/HandlerExecutor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package webmvc.org.springframework.web.servlet.mvc; | ||
|
||
import jakarta.servlet.http.HttpServletRequest; | ||
import jakarta.servlet.http.HttpServletResponse; | ||
import webmvc.org.springframework.web.servlet.ModelAndView; | ||
import webmvc.org.springframework.web.servlet.view.JspView; | ||
|
||
public class HandlerExecutor { | ||
|
||
private final HandlerAdapterRegistry handlerAdapterRegistry; | ||
|
||
public HandlerExecutor(final HandlerAdapterRegistry handlerAdapterRegistry) { | ||
this.handlerAdapterRegistry = handlerAdapterRegistry; | ||
} | ||
|
||
public ModelAndView handle( | ||
final HttpServletRequest request, | ||
final HttpServletResponse response, | ||
final Object handler | ||
) throws Exception { | ||
final HandlerAdapter handlerAdapter = handlerAdapterRegistry.getHandlerAdapter(handler); | ||
return handlerAdapter.handle(request, response, handler); | ||
} | ||
|
||
public ModelAndView handleNotFound() { | ||
return new ModelAndView(new JspView("404.jsp")); | ||
} | ||
} |
8 changes: 0 additions & 8 deletions
8
mvc/src/main/java/webmvc/org/springframework/web/servlet/mvc/asis/Controller.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
현재 이 부분을 보면
☺️
HandlerExecutor
의 경우DispatcherServlet
의init()
메소드에서 초기화가 되는데HandlerMapping
과HandlerAdapter
의 경우에는DispatcherServletInitializer
에서 값을 추가하는 방식으로 구현을 해주셨어요. 이 부분을 분리해서 값을 추가해주신 이유가 있을까요?혹시 AnnotationHandler의 basePackage 설정을 위함일까요?
엔초의 생각흐름이 궁금합니다!
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.
addHandlerMapping
과addHandlerAdapter
는DispatcherServletInitializer
의onStartUp()
에서 직접 호출하고 있고,DispatcherServlet
의init()
은onStartUp()
이 끝난 후에 호출이 되고 있습니다.HandlerExecutor
는HandlerAdapterRegistry
를 사용하기 때문에HandlerAdapterRegistry
에 대한 설정이 끝난 이후에 사용되어야 한다고 생각했습니다.init()
메서드가HandlerAdapterRegistry
를 설정해주는onStartUp()
이 끝난 후에 호출되기 때문에 이렇게 분리하면 더 명확하다고 생각했습니다.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.
넵 이해 완료했습니다! 자세하게 답변해주셔서 감사합니다!