-
Notifications
You must be signed in to change notification settings - Fork 302
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
Changes from 1 commit
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
f90ba2b
feat: JsonView 구현
carsago 1754fe7
refactor: Login 로직 annotation Controller로 동작하도록 변경
carsago a7e2926
refactor: logout 로직 annotation Controller로 동작하도록 변경
carsago 10b6852
refactor: ForwardController 어노테이션 기반으로 변경
carsago 5369e98
refactor: 사용하지 않게된 ManulHandler 관련된 클래스 제거
carsago 1f003db
chore: DispatcherServlet 패키지 변경
carsago 77a04c2
feat: UserController 추가
carsago 65b2bc0
refactor: JsonView가 요구사항에 맞게 view를 반환하도록 변경
carsago f538a5b
style: 개행 수정
carsago bf4630c
refactor: 개행 HandlerMapping 구현체 변경
carsago 0fa520f
refactor: DispatcherServlet에서 JspView 의존성 제거
carsago 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
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
19 changes: 19 additions & 0 deletions
19
app/src/main/java/com/techcourse/exception/NotFoundExceptionHandler.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,19 @@ | ||
package com.techcourse.exception; | ||
|
||
import webmvc.org.springframework.web.servlet.ModelAndView; | ||
import webmvc.org.springframework.web.servlet.mvc.tobe.exception.HandlerNotFoundException; | ||
import webmvc.org.springframework.web.servlet.mvc.tobe.handler.ExceptionHandler; | ||
import webmvc.org.springframework.web.servlet.view.JspView; | ||
|
||
public class NotFoundExceptionHandler implements ExceptionHandler { | ||
|
||
@Override | ||
public boolean support(Throwable ex) { | ||
return ex instanceof HandlerNotFoundException; | ||
} | ||
|
||
@Override | ||
public ModelAndView handle() { | ||
return new ModelAndView(new JspView("/404.jsp")); | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...techcourse/UncheckedServletException.java → .../exception/UncheckedServletException.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
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
23 changes: 13 additions & 10 deletions
23
...ain/java/webmvc/org/springframework/web/servlet/mvc/tobe/exception/ExceptionResolver.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 |
---|---|---|
@@ -1,21 +1,24 @@ | ||
package webmvc.org.springframework.web.servlet.mvc.tobe.exception; | ||
|
||
import com.sun.jdi.InternalException; | ||
import java.util.List; | ||
import webmvc.org.springframework.web.servlet.ModelAndView; | ||
import webmvc.org.springframework.web.servlet.view.JspView; | ||
import webmvc.org.springframework.web.servlet.mvc.tobe.handler.ExceptionHandler; | ||
|
||
public class ExceptionResolver { | ||
|
||
public ModelAndView handle(Throwable ex) { | ||
ModelAndView mv = null; | ||
if (ex instanceof HandlerNotFoundException) { | ||
mv = new ModelAndView(new JspView("/404.jsp")); | ||
} | ||
private final List<ExceptionHandler> handlers; | ||
|
||
if (mv == null) { | ||
return new ModelAndView(new JspView("/500.jsp")); | ||
} | ||
public ExceptionResolver(List<ExceptionHandler> handlers) { | ||
this.handlers = handlers; | ||
} | ||
|
||
return mv; | ||
public ModelAndView handle(Throwable ex) { | ||
ExceptionHandler handler = handlers.stream() | ||
.filter(it -> it.support(ex)) | ||
.findFirst() | ||
.orElseThrow(() -> new InternalException()); | ||
return handler.handle(); | ||
Comment on lines
+16
to
+21
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 오 이렇게 처리해주셨군요 ㅎㅎ 너무 좋아요. |
||
} | ||
} | ||
|
10 changes: 10 additions & 0 deletions
10
...c/main/java/webmvc/org/springframework/web/servlet/mvc/tobe/handler/ExceptionHandler.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,10 @@ | ||
package webmvc.org.springframework.web.servlet.mvc.tobe.handler; | ||
|
||
import webmvc.org.springframework.web.servlet.ModelAndView; | ||
|
||
public interface ExceptionHandler { | ||
|
||
boolean support(Throwable ex); | ||
|
||
ModelAndView handle(); | ||
} |
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.
마땅히 남길만한 곳이 없어서 여기에 남겨요!
이번 단계를 구현하면서 고민했던 부분이 있어서요! 오리가 구현해주신
ExceptionResolver
에서 예외처리를 해주기 위해 특정 jsp의 이름이 들어간JspView
를 생성하고 있는데요. 그렇다면 만약 app에 해당 이름을 가진 파일이 없다면 어떻게 되는것인가요? 구현해주신DispatcherServlet
을 사용하기 위해서는 무조건404.jsp
와500.jsp
를 구현해주는 것을 강제해야 할 것 같네요. 이렇게 되면 조금 빡빡한(?) 구조가 될 것 같아서 고민이네요!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.
이 부분은 생각해보니 좀 마음에 들지 않는 부분이네요.
중간에 interface를 쓰는 방식으로 개선해보았어요.