-
Notifications
You must be signed in to change notification settings - Fork 302
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[MVC 구현하기 - 2단계] 매튜(김재연) 미션 제출합니다. (#508)
* refactor : Register(View)Controller 통합 * refactor : interface HandlerExecution 을 추가하고, Manual, Annotation HandlerExecution 들이 이를 구현 * refactor : DispatcherServlet Service 에서 ModelAndView 를 처리하도록 구현 * refactor : HandlerMapping 추가 * refactor : DispatcherServle이 HandlerMapping 을 가질 수 있도록 구현 * refactor : JsonView getViewName() 이 의미 없는 값을 반환하도록 수정 * fix : basePackages 수정 * refactor : Exception 처리 * refactor : 기존 Register(View)Controller 복구 * refactor : 로그인 화면에서 회원가입시 이동하는 URL `/register/view` -> `/register` 로 변경 * refactor : 필요없는 형변환 삭제 * refactor : Annotation 기반 Controller 가 더 우선적으로 선택될 수 있도록 수정 * refactor : HandlerExecution 추상화 제거 * refactor : HandlerMapping 추상화
- Loading branch information
Showing
19 changed files
with
220 additions
and
40 deletions.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package com.techcourse; | ||
|
||
import jakarta.servlet.http.HttpServletRequest; | ||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.Objects; | ||
import java.util.Optional; | ||
import webmvc.org.springframework.web.servlet.mvc.tobe.HandlerExecution; | ||
import webmvc.org.springframework.web.servlet.mvc.tobe.HandlerMapping; | ||
|
||
public class HandlerMappings { | ||
|
||
private final List<HandlerMapping> handlerMappings; | ||
|
||
public HandlerMappings(List<HandlerMapping> handlerMappings) { | ||
this.handlerMappings = new ArrayList<>(handlerMappings); | ||
} | ||
|
||
public HandlerMappings() { | ||
this(Collections.emptyList()); | ||
} | ||
|
||
public void addHandlerMapping(HandlerMapping handlerMapping) { | ||
handlerMapping.initialize(); | ||
handlerMappings.add(handlerMapping); | ||
} | ||
|
||
public Optional<HandlerExecution> getHandler(HttpServletRequest request) { | ||
return handlerMappings.stream() | ||
.map(handlerMapping -> handlerMapping.getHandler(request)) | ||
.filter(Objects::nonNull) | ||
.findFirst(); | ||
} | ||
|
||
} |
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
39 changes: 39 additions & 0 deletions
39
app/src/main/java/com/techcourse/controller/RegisterAnnotationController.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,39 @@ | ||
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 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 RegisterAnnotationController { | ||
|
||
@RequestMapping(value = "/register", method = RequestMethod.POST) | ||
public ModelAndView save(HttpServletRequest req, HttpServletResponse res) { | ||
User user = new User( | ||
2, | ||
req.getParameter("account"), | ||
req.getParameter("password"), | ||
req.getParameter("email") | ||
); | ||
|
||
InMemoryUserRepository.save(user); | ||
|
||
return new ModelAndView( | ||
new JspView("redirect:/index.jsp") | ||
); | ||
} | ||
|
||
@RequestMapping(value = "/register", method = RequestMethod.GET) | ||
public ModelAndView show(HttpServletRequest req, HttpServletResponse res) { | ||
return new ModelAndView( | ||
new JspView("/register.jsp") | ||
); | ||
} | ||
|
||
} |
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
17 changes: 17 additions & 0 deletions
17
mvc/src/main/java/web/org/springframework/http/HttpStatus.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,17 @@ | ||
package web.org.springframework.http; | ||
|
||
public enum HttpStatus { | ||
|
||
NOT_FOUND(404); | ||
|
||
private final int value; | ||
|
||
HttpStatus(int value) { | ||
this.value = value; | ||
} | ||
|
||
public int getValue() { | ||
return value; | ||
} | ||
|
||
} |
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
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
Oops, something went wrong.