-
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
Conversation
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.
안녕하세요 엔초!
3단계 엄청 빠르게 구현해주셨네요! 👍
코드가 전반적으로 간결하고 큰 흐름이 잘 읽혀서 리뷰하기 수월했습니다!👍
간단하게 의견을 물어보는 것과 수정할 부분에 대해서 리뷰남겼는데 확인바랍니다!
public void init() { | ||
handlerMappingRegistry.addHandlerMapping(new ManualHandlerMapping()); | ||
handlerMappingRegistry.addHandlerMapping(new AnnotationHandlerMapping(Application.class.getPackageName() + ".*")); | ||
handlerAdapterRegistry.addHandlerAdapter(new ControllerHandlerAdapter()); | ||
handlerAdapterRegistry.addHandlerAdapter(new HandlerExecutionHandlerAdapter()); | ||
handlerExecutor = new HandlerExecutor(handlerAdapterRegistry); | ||
} | ||
|
||
public void addHandlerMapping(final HandlerMapping handlerMapping) { | ||
handlerMappingRegistry.addHandlerMapping(handlerMapping); | ||
} | ||
|
||
public void addHandlerAdapter(final HandlerAdapter handlerAdapter) { | ||
handlerAdapterRegistry.addHandlerAdapter(handlerAdapter); | ||
} |
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.
넵 이해 완료했습니다! 자세하게 답변해주셔서 감사합니다!
final Optional<Object> nullableHandler = handlerMappingRegistry.getHandler(request); | ||
|
||
if (nullableHandler.isEmpty()) { | ||
response.setStatus(HttpServletResponse.SC_NOT_FOUND); | ||
render(new ModelAndView(new JspView("404.jsp")), request, response); | ||
return; | ||
} | ||
|
||
final Object handler = nullableHandler.get(); | ||
try { | ||
final HandlerAdapter handlerAdapter = handlerAdapterRegistry.getHandlerAdapter(handler); | ||
final ModelAndView modelAndView = handlerAdapter.handle(request, response, handler); | ||
final ModelAndView modelAndView = handlerExecutor.handle(request, response, handler); | ||
render(modelAndView, request, response); | ||
} catch (Exception e) { | ||
throw new RuntimeException(e); |
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
를 이번에 도입해주셨는데 HandlerExecutor
내부에 HanderMappingResitry
를 가지고 있고 handler
를 찾아와서 실행시켜주는 것 같습니다. 하지만 현재 코드를 보면 404.jsp
를 나타낼 때에는 handlerMappingResitry
에서 직접꺼내와서 작업을 진행하는 것도 작업이 있는데 이 부분도 HandlerExecutor 내부에서 처리하는 방식으로 수정하면 좋을 것 같습니다!
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.
handleNotFound 메서드를 추가해서 404 ModelAndView를 반환하도록 수정했습니다!
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.
확인했습니다!
final String body = objectMapper.writeValueAsString(model); | ||
response.setContentType(MediaType.APPLICATION_JSON_UTF8_VALUE); | ||
response.getWriter().write(body); |
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.
model에 데이터가 1개면 값을 그대로 반환하고 2개 이상이면 Map 형태 그대로 JSON으로 변환해서 반환한다.
힌트에 위와 같이 요구조건이 있는데 그 부분이 지켜지지 않은 것 같습니다. 물론 결과는 지금과 같게 나오기는 합니다!
그래도 수정 한번 부탁드립니다!
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.
아 맞다.. 나중에 하기로 하고 까먹었네요ㅠ
final String requestURI = request.getRequestURI(); | ||
log.debug("Method : {}, Request URI : {}", request.getMethod(), requestURI); | ||
|
||
final Optional<Object> nullableHandler = handlerMappingRegistry.getHandler(request); | ||
|
||
if (nullableHandler.isEmpty()) { | ||
response.setStatus(HttpServletResponse.SC_NOT_FOUND); | ||
render(new ModelAndView(new JspView("404.jsp")), request, response); |
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.
안녕하세요 엔초!
리뷰도 빠르게 반영해주셨군요!👍👍
이번 리뷰를 진행하면서 엔초의 생각을 들어볼 수 있는 시간이 되어서 저도 많이 배울 수 있었습니다!
더이상 고칠 부분이 없다고 생각이 들어서 approve 드립니다!
이번 미션도 고생하셨습니다.
다음 미션도 화이팅입니다!
안녕하세요 아코! 2단계 때 정성스러운 리뷰 정말 감사합니다.
질문 남겨주신 부분에 대해 답변 남겨놨습니다~ 2단계 pr
총 8개의 커밋 중 앞의 4개(범위)는 2단계에서 리뷰해 주신 내용 적용한 것과 간단한 리팩토링(HandlerExecutor 추가 및 DispatcherServletInitializer에서 핸들러 매핑과 핸들러 어댑터를 추가하도록 변경)에 해당하는 부분이고,
뒤에 있는 4개의 커밋(범위)이 3단계 구현에 해당합니다.
이번 리뷰도 잘 부탁드립니다!