-
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단계] 로이(김덕우) 미션 제출합니다. #631
Merged
Merged
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
b2c0748
feat: JspView 클래스 구현 및 DispatcherServlet 로직 수정
the9kim c8b9e42
feat: JsonView 클래스 구현 및 MediaType 추가
the9kim fb5e04e
feat: legacy mvc 제거 및 legacy 컨트롤러 어노테이션 기반으로 변경
the9kim 1e1974a
feat: stream을 적용하여 메서드 로직 변경(망고 피드백 반영)
the9kim 756dc31
refactor: DispatcherServletInitializer 패키지 변경
the9kim 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
24 changes: 0 additions & 24 deletions
24
app/src/main/java/com/techcourse/ManualHandlerAdapter.java
This file was deleted.
Oops, something went wrong.
39 changes: 0 additions & 39 deletions
39
app/src/main/java/com/techcourse/ManualHandlerMapping.java
This file was deleted.
Oops, something went wrong.
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: 11 additions & 6 deletions
17
app/src/main/java/com/techcourse/controller/LoginViewController.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,22 +1,27 @@ | ||
package com.techcourse.controller; | ||
|
||
import context.org.springframework.stereotype.Controller; | ||
import jakarta.servlet.http.HttpServletRequest; | ||
import jakarta.servlet.http.HttpServletResponse; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import webmvc.org.springframework.web.servlet.mvc.asis.Controller; | ||
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; | ||
|
||
public class LoginViewController implements Controller { | ||
@Controller | ||
public class LoginViewController { | ||
|
||
private static final Logger log = LoggerFactory.getLogger(LoginViewController.class); | ||
|
||
@Override | ||
public String execute(final HttpServletRequest req, final HttpServletResponse res) throws Exception { | ||
@RequestMapping(value = "/login/view", method = RequestMethod.GET) | ||
public ModelAndView getLoginView(final HttpServletRequest req, final HttpServletResponse res) { | ||
return UserSession.getUserFrom(req.getSession()) | ||
.map(user -> { | ||
log.info("logged in {}", user.getAccount()); | ||
return "redirect:/index.jsp"; | ||
return new ModelAndView(new JspView("redirect:/index.jsp")); | ||
}) | ||
.orElse("/login.jsp"); | ||
.orElse(new ModelAndView(new JspView("/login.jsp"))); | ||
} | ||
} |
15 changes: 10 additions & 5 deletions
15
app/src/main/java/com/techcourse/controller/LogoutController.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,15 +1,20 @@ | ||
package com.techcourse.controller; | ||
|
||
import context.org.springframework.stereotype.Controller; | ||
import jakarta.servlet.http.HttpServletRequest; | ||
import jakarta.servlet.http.HttpServletResponse; | ||
import webmvc.org.springframework.web.servlet.mvc.asis.Controller; | ||
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; | ||
|
||
public class LogoutController implements Controller { | ||
@Controller | ||
public class LogoutController { | ||
|
||
@Override | ||
public String execute(final HttpServletRequest req, final HttpServletResponse res) throws Exception { | ||
@RequestMapping(value = "/logout", method = RequestMethod.GET) | ||
public ModelAndView logout(final HttpServletRequest req, final HttpServletResponse res) { | ||
final var session = req.getSession(); | ||
session.removeAttribute(UserSession.SESSION_KEY); | ||
return "redirect:/"; | ||
return new ModelAndView(new JspView("redirect:/")); | ||
} | ||
} |
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
15 changes: 10 additions & 5 deletions
15
app/src/main/java/com/techcourse/controller/RegisterViewController.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,13 +1,18 @@ | ||
package com.techcourse.controller; | ||
|
||
import context.org.springframework.stereotype.Controller; | ||
import jakarta.servlet.http.HttpServletRequest; | ||
import jakarta.servlet.http.HttpServletResponse; | ||
import webmvc.org.springframework.web.servlet.mvc.asis.Controller; | ||
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; | ||
|
||
public class RegisterViewController implements Controller { | ||
@Controller | ||
public class RegisterViewController { | ||
|
||
@Override | ||
public String execute(final HttpServletRequest req, final HttpServletResponse res) throws Exception { | ||
return "/register.jsp"; | ||
@RequestMapping(value = "/register/view", method = RequestMethod.GET) | ||
public ModelAndView getRegisterView(final HttpServletRequest req, final 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
8 changes: 0 additions & 8 deletions
8
mvc/src/main/java/webmvc/org/springframework/web/servlet/mvc/asis/Controller.java
This file was deleted.
Oops, something went wrong.
20 changes: 0 additions & 20 deletions
20
mvc/src/main/java/webmvc/org/springframework/web/servlet/mvc/asis/ForwardController.java
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -16,11 +16,9 @@ public void addHandlerAdapter(HandlerAdapter handlerAdapter) { | |
} | ||
|
||
public HandlerAdapter getHandlerAdapter(Object handler) { | ||
for (HandlerAdapter handlerAdapter : this.handlerAdapters) { | ||
if (handlerAdapter.isSupport(handler)) { | ||
return handlerAdapter; | ||
} | ||
} | ||
throw new IllegalArgumentException("해당 handler를 찾을 수 없습니다."); | ||
return this.handlerAdapters.stream() | ||
.filter(handlerAdapter -> handlerAdapter.isSupport(handler)) | ||
.findFirst() | ||
.orElseThrow(() -> new IllegalArgumentException("해당 handler를 찾을 수 없습니다.")); | ||
Comment on lines
+19
to
+22
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. 피드백 반영 좋아요 👍👍 |
||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
mvc/src/main/java/webmvc/org/springframework/web/servlet/view/JsonView.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,14 +1,29 @@ | ||
package webmvc.org.springframework.web.servlet.view; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import jakarta.servlet.http.HttpServletRequest; | ||
import jakarta.servlet.http.HttpServletResponse; | ||
import web.org.springframework.http.MediaType; | ||
import webmvc.org.springframework.web.servlet.View; | ||
|
||
import java.util.Map; | ||
|
||
public class JsonView implements View { | ||
|
||
private static final ObjectMapper MAPPER = new ObjectMapper(); | ||
private static final int DEFAULT_RETURN_SIZE = 1; | ||
|
||
@Override | ||
public void render(final Map<String, ?> model, final HttpServletRequest request, HttpServletResponse response) throws Exception { | ||
String jsonValue = MAPPER.writeValueAsString(model); | ||
|
||
if (model.size() == DEFAULT_RETURN_SIZE) { | ||
response.setContentType(MediaType.TEXT_PLAIN_UTF8_VALUE); | ||
response.getWriter().write(jsonValue); | ||
return; | ||
} | ||
|
||
response.setContentType(MediaType.APPLICATION_JSON_UTF8_VALUE); | ||
response.getWriter().write(jsonValue); | ||
} | ||
} |
Oops, something went wrong.
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.
지금 Controller가 제대로 동작하고 있는지
http://localhost:8080/login/view
와 같은 url로 확인했을 때, 제대로 된 페이지 뷰가 나오지 않는 걸 확인했어요!오늘 강의 초반에도 언급되었던
DispatcherServletInitializer
의 패키지 위치 때문인 것 같아요!