Skip to content
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단계] 오리(오현서) 미션 제출합니다. #543

Merged
merged 11 commits into from
Sep 28, 2023

Conversation

carsago
Copy link

@carsago carsago commented Sep 23, 2023

안녕하세요 밀리 MVC 미션의 마지막 단계네요.
이번 PR에서는 요구사항을 충족 시키는 것에 중점을 뒀습니다.

그리고 큰 부분은 아니지만, 기존의 컨트롤러에선 LoginView(GET 요청)와 Login(POST 요청)이 분리되어 있고, 페이지 요청은 login/view 로 매핑되어 있었는데, 둘다 /login을 사용하고 http method로 구분하도록 변경했습니다. 이유는 그게 깔끔한거 같아서..

@carsago carsago self-assigned this Sep 23, 2023
@Songusika Songusika deleted the branch woowacourse:carsago September 23, 2023 17:44
@Songusika Songusika closed this Sep 23, 2023
@Songusika Songusika reopened this Sep 23, 2023
Copy link

@miseongk miseongk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

안녕하세요 오리!
리뷰 요청 빨리 주셨는데 늦어서 죄송합니다 😭
잘해주셔서 크게 변경될 부분이 없을 것 같아 이대로 머지해도 되지만,
오리의 의견이 궁금한게 있어서 Request change 할게요.

@@ -39,14 +36,14 @@ public void init() {

private HandlerMapping initHandlerMappings() {
HandlerMapping handlerMapping = new HandlerMappingComposite(
List.of(new ManualHandlerMapping(), new AnnotationHandlerMapping("com.techcourse.controller")));
List.of(new AnnotationHandlerMapping("com.techcourse.controller")));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mvc 패키지에 있는 DispatcherServlet에서 특정 패키지에 의존적이게 되었네요.
다른 방법은 없을까요?!

Copy link
Author

@carsago carsago Sep 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

전 지정한 패키지만 스캔하고 싶어서 이렇게 명시적으로 하는 방식을 더 선호했어요.
조금 변경에 취약하더라도(그럼에도, 바뀔 가능성이 크지 않은 부분이기에 리스크가 크지 않다고 느꼈어요.) 예상치 못한 패키지를 스캔 하는 것에 대한 리스크가 조금 두려웠어요.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

그렇군요.
저는 DispatcherServlet이 mvc 패키지 하위에 있는 이상 개발자가 관여하는 부분이 아니라 프레임워크 부분이라고 생각했고, 개발자가 직접 지정할 수 없다고 생각했어요!

@@ -39,14 +36,14 @@ public void init() {

private HandlerMapping initHandlerMappings() {
HandlerMapping handlerMapping = new HandlerMappingComposite(

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이 부분은 앞서 오리가 예시로 들어주었던 부분과 달라서 코멘트 남겨보아요!
만약 핸들러 매핑이 하나만 있다면 해당 핸들러 매핑을 직접 대입해주는 것이 이해하기 쉬운 코드라고 하셨는데, HandlerMappingComposite에 넣은 이유가 무엇인가요?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이거 솔직히 말하면 바꾸는거 까먹었습니다.

handlerMapping.initialize();
return handlerMapping;
}

private HandlerAdapterFinder initHandlerAdapterFinder() {
return new HandlerAdapterFinder(
List.of(new ManualHandlerAdapter(), new AnnotationHandlerAdapter()));
List.of(new AnnotationHandlerAdapter()));
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

마땅히 남길만한 곳이 없어서 여기에 남겨요!
이번 단계를 구현하면서 고민했던 부분이 있어서요! 오리가 구현해주신 ExceptionResolver에서 예외처리를 해주기 위해 특정 jsp의 이름이 들어간 JspView를 생성하고 있는데요. 그렇다면 만약 app에 해당 이름을 가진 파일이 없다면 어떻게 되는것인가요? 구현해주신 DispatcherServlet을 사용하기 위해서는 무조건 404.jsp500.jsp를 구현해주는 것을 강제해야 할 것 같네요. 이렇게 되면 조금 빡빡한(?) 구조가 될 것 같아서 고민이네요!

Copy link
Author

@carsago carsago Sep 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이 부분은 생각해보니 좀 마음에 들지 않는 부분이네요.
중간에 interface를 쓰는 방식으로 개선해보았어요.

private static final Logger log = LoggerFactory.getLogger(LoginController.class);

@RequestMapping(value = "/login", method = RequestMethod.POST)
public ModelAndView login(final HttpServletRequest req, final HttpServletResponse res) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

기존의 반환타입을 변경하지 않고 String도 호환되게 할 수도 있을 것 같아요.
하지만 변경하라는 말은 절대 아닙니다!!

Copy link
Author

@carsago carsago Sep 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

String을 받든 Model, View 무엇을 받든 ModelAndView로 만들어주는 클래스가 있으면 확장성 있겠네요.
다만 지금은 ModelAndView로만 받는 단순한 방식도 복잡하지 않기 때문에 괜찮다고 느껴져요.

Copy link

@miseongk miseongk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

안녕하세요 오리~!
mvc 미션 정말 수고 많으셨어요!
미션이 되게 오랫동안 지속되어서 힘드셨을 것 같은데,
끝까지 고민 많이 해주시고 구조도 계속 바꾸시는 것 보면서 정말 감탄했어요.
저는 계속 기존 Spring MVC 프레임워크에 갇혀서 넓게 생각하지 못했던 것 같은데
오리만의 생각을 잘 말씀해주셔서 정말 많이 배웠고 재밌었어요 😊
즐거운 추석 보내시고 다음 미션도 화이팅하세요!!

Comment on lines +16 to +21
public ModelAndView handle(Throwable ex) {
ExceptionHandler handler = handlers.stream()
.filter(it -> it.support(ex))
.findFirst()
.orElseThrow(() -> new InternalException());
return handler.handle();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

오 이렇게 처리해주셨군요 ㅎㅎ 너무 좋아요.
여기서 추가적으로 만약 개발자가 ExceptionHandler를 구현하지 않아서 아무것도 support하지 않을때, mvc 자체적으로 예외 화면을 보여주는 식으로 해볼수도 있겠네요!

@@ -39,14 +36,14 @@ public void init() {

private HandlerMapping initHandlerMappings() {
HandlerMapping handlerMapping = new HandlerMappingComposite(
List.of(new ManualHandlerMapping(), new AnnotationHandlerMapping("com.techcourse.controller")));
List.of(new AnnotationHandlerMapping("com.techcourse.controller")));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

그렇군요.
저는 DispatcherServlet이 mvc 패키지 하위에 있는 이상 개발자가 관여하는 부분이 아니라 프레임워크 부분이라고 생각했고, 개발자가 직접 지정할 수 없다고 생각했어요!

@miseongk miseongk merged commit 9183292 into woowacourse:carsago Sep 28, 2023
1 check failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants