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 구현하기 - 1단계] 애쉬(정설희) 미션 제출합니다. #336

Merged
merged 5 commits into from
Sep 13, 2023

Conversation

xxeol2
Copy link

@xxeol2 xxeol2 commented Sep 12, 2023

안녕하세요 썬샷!! ☀️

AnnotationHandlerMapping 클래스를 리플렉션을 통해 구현해보았습니다!
app쪽 코드랑 뷰 관련 코드들은 이후 단계에서 진행하는 것 같아 우선 간단하게 어노테이션 기반 맵핑 코드만 작성했습니다!
(AnnotationHandlerMapping과 HandlerExecution 클래스만 변경해서.. 제가 뭔가 요구사항을 놓친건가 싶네요)

이번 단계에서 @RequestParam @PathVariable 어노테이션도 추가적으로 구현을 하는건지 잘 모르겠네요!
구현이 필요하다면 코멘트 남겨주시면 추가 구현 하도록 하겠습니다아

잘 부탁 드립니다 🙇🏻‍♀️

@xxeol2 xxeol2 changed the base branch from main to xxeol2 September 12, 2023 17:28
Copy link

@Ohjintaek Ohjintaek left a comment

Choose a reason for hiding this comment

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

수고하셨어요 애쉬!!
코드가 깔끔하고 이해도 잘 됐습니다. 너무 구현 잘 해주셔서 제가 미션 시작할 때 영향을 받을 것만 같은 기분이네요. 제 미션 진행하고 리뷰했으면 하는 아쉬움이 남습니다ㅎㅎㅎ
몇 군데 질문을 달아놓았는데 2단계 진행하면서 답변 달아주셔도 충분할 거 같아서 바로 merge할게요~😊
2단계도 화이팅입니다


public void initialize() {
Reflections reflections = new Reflections(basePackage);
Set<Class<?>> controllers = reflections.getTypesAnnotatedWith(Controller.class, true);

Choose a reason for hiding this comment

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

refelections.getTypesAnnotatedWith(Controller.class)를 호출해도 테스트들을 잘 통과하던데 isHonorInherited 파라미터를 true로 전달한 이유는 무엇인가요?
@Class 어노테이션을 처리하기 위해서 어떤 점을 고려해서 사용한 건지 궁금합니다.

private void mapController(final Class<?> clazz) {
Method[] methods = clazz.getDeclaredMethods();
for (final Method method : methods) {
mapControllerMethod(createControllerInstance(clazz), method, getRequestPath(clazz));

Choose a reason for hiding this comment

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

저는 메서드들이 등장한 순서대로 정렬하는 방법이 코드를 읽을 때 편해서 더 선호하는데 애쉬의 생각은 어떤가요?

}
}

public String getRequestPath(final Class<?> clazz) {

Choose a reason for hiding this comment

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

이 메서드는 왜 public으로 열어두셨나요?

Copy link
Author

Choose a reason for hiding this comment

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

ide 메서드 추출 기능으로 하다가 실수했나봐요 🥲
다시 private으로 닫아두겠습니다!

private void mapController(final Class<?> clazz) {
Method[] methods = clazz.getDeclaredMethods();
for (final Method method : methods) {
mapControllerMethod(createControllerInstance(clazz), method, getRequestPath(clazz));

Choose a reason for hiding this comment

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

mapControllerMethod에서 특정 클래스에서 핸들러에 등록할 메서드를 찾는 과정에서 메서드마다 클래스의 인스턴스를 새로 만들어주고 있는데 for문 이전에 하나만 만들어서 재사용하는 건 안 되나요?
학습 테스트도 미션 시작도 안 한 상태라 기반 지식이 전혀 없는 상태라 궁금하네요...

modelAndView.addObject("id", request.getAttribute("id"));
return modelAndView;
}
@RequestMapping(value = "/update-test", method = {RequestMethod.PUT, RequestMethod.PATCH})

Choose a reason for hiding this comment

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

RequestMethod[] 형태로 가져오는데 method를 두 개 가지는 메서드를 만들어서 테스트해주신 점 너무 좋았습니다 👍👍

import webmvc.org.springframework.web.servlet.view.JspView;

@Controller
@RequestMapping("/test")

Choose a reason for hiding this comment

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

Class 레벨에 달린 @RequestMapping 까지 잘 처리하는군요 😆

@Ohjintaek Ohjintaek merged commit e6916f8 into woowacourse:xxeol2 Sep 13, 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.

2 participants