-
Notifications
You must be signed in to change notification settings - Fork 381
[MVC 구현하기 - 3단계] 채채 (신채원) 미션 제출합니다 #613
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
Changes from 8 commits
bc9dc2a
3923751
4c1edbe
1e23c9f
a421497
7b2cbbc
82b6dd7
008358b
ef44a00
ee3455f
97fd8e5
7f80dae
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,6 @@ | |
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import web.org.springframework.web.WebApplicationInitializer; | ||
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. 채채는 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. DispatcherServletInitializer가 app패키지에 의존하고있어서 따로 분리하지 못하였습니다..! 이부분에 대해서 조이는 어떻게 처리하셨나요!? 저는 이부분에대해서 전혀 감을 잡지 못하였습니다아... 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. 저도 DispatcherServletInitializer는 app 패키지에 그냥 두고 DispatcherServlet만 이동했어요! |
||
import webmvc.org.springframework.web.servlet.mvc.asis.ControllerHandlerAdapter; | ||
import webmvc.org.springframework.web.servlet.mvc.tobe.AnnotationHandlerMapping; | ||
import webmvc.org.springframework.web.servlet.mvc.tobe.HandlerExecutionHandlerAdapter; | ||
|
||
|
@@ -21,9 +20,7 @@ public class DispatcherServletInitializer implements WebApplicationInitializer { | |
@Override | ||
public void onStartup(final ServletContext servletContext) { | ||
final DispatcherServlet dispatcherServlet = new DispatcherServlet(); | ||
dispatcherServlet.addHandlerMapping(new ManualHandlerMapping()); | ||
dispatcherServlet.addHandlerMapping(new AnnotationHandlerMapping("com")); | ||
dispatcherServlet.addHandlerAdapter(new ControllerHandlerAdapter()); | ||
dispatcherServlet.addHandlerAdapter(new HandlerExecutionHandlerAdapter()); | ||
|
||
final var registration = servletContext.addServlet(DEFAULT_SERVLET_NAME, dispatcherServlet); | ||
|
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.techcourse.controller; | ||
|
||
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 IndexController { | ||
|
||
@RequestMapping(value = "/", method = RequestMethod.GET) | ||
public ModelAndView index(final HttpServletRequest req, | ||
final HttpServletResponse res) { | ||
Comment on lines
+15
to
+16
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. 요기도 request, response로 통일해주면 좋을 것 같네용 |
||
return new ModelAndView(new JspView("index.jsp")); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,34 @@ | ||
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 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.mvc.asis.Controller; | ||
import webmvc.org.springframework.web.servlet.view.JspView; | ||
|
||
public class LoginViewController implements Controller { | ||
@Controller | ||
public class LoginViewController { | ||
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. Login 관련 메서드들을 하나의 컨트롤러에서 관리할수도 있을 것 같은데 |
||
|
||
private static final Logger log = LoggerFactory.getLogger(LoginViewController.class); | ||
|
||
@Override | ||
public String execute(final HttpServletRequest req, final HttpServletResponse res) { | ||
return UserSession.getUserFrom(req.getSession()) | ||
@RequestMapping(value = "/login/view", method = RequestMethod.GET) | ||
public ModelAndView loginView(final HttpServletRequest request, | ||
final HttpServletResponse response) { | ||
final String path = execute(request, response); | ||
return new ModelAndView(new JspView(path)); | ||
} | ||
|
||
private String execute(final HttpServletRequest request, | ||
final HttpServletResponse response) { | ||
return UserSession.getUserFrom(request.getSession()) | ||
.map(user -> { | ||
log.info("logged in {}", user.getAccount()); | ||
return "redirect:/index.jsp"; | ||
}) | ||
.orElse("/login.jsp"); | ||
} | ||
|
||
@RequestMapping(value = "/login/view", method = RequestMethod.GET) | ||
public ModelAndView loginView(HttpServletRequest req, HttpServletResponse res) { | ||
String path = execute(req, res); | ||
return new ModelAndView(new JspView(path)); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,21 @@ | ||
package com.techcourse.controller; | ||
|
||
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.mvc.asis.Controller; | ||
import webmvc.org.springframework.web.servlet.view.JspView; | ||
|
||
public class LogoutController implements Controller { | ||
|
||
@Override | ||
public String execute(final HttpServletRequest req, final HttpServletResponse res) { | ||
final var session = req.getSession(); | ||
session.removeAttribute(UserSession.SESSION_KEY); | ||
return "redirect:/"; | ||
} | ||
@Controller | ||
public class LogoutController { | ||
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. 로그아웃 기능이 정상 작동 하지 않는 것 같아요~ 확인 한번 해보시면 좋을 것 같아요! 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. post로 되어있군요..ㅠㅠ 수정하겠습니다~! |
||
|
||
@RequestMapping(value = "/logout", method = RequestMethod.POST) | ||
public ModelAndView logout(HttpServletRequest req, HttpServletResponse res) { | ||
String path = execute(req, res); | ||
return new ModelAndView(new JspView(path)); | ||
public ModelAndView logout(final HttpServletRequest request, | ||
final HttpServletResponse response) { | ||
final var session = request.getSession(); | ||
session.removeAttribute(UserSession.SESSION_KEY); | ||
return new ModelAndView(new JspView("redirect:/")); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,19 @@ | ||
package com.techcourse.controller; | ||
|
||
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.mvc.asis.Controller; | ||
import webmvc.org.springframework.web.servlet.view.JspView; | ||
|
||
public class RegisterViewController implements Controller { | ||
|
||
@Override | ||
public String execute(final HttpServletRequest req, final HttpServletResponse res) { | ||
return "/register.jsp"; | ||
} | ||
@Controller | ||
public class RegisterViewController { | ||
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. 마찬가지로 RegisterViewController와 RegisterController를 분리하신 이유가 궁금합니다! 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. 음 위 3개의 질문에 대해서 뷰를 분리한 이유는 사실 크게 없는데..요청 uri가 달라서 분리를 했습니다! |
||
|
||
@RequestMapping(value = "/register/view", method = RequestMethod.GET) | ||
public ModelAndView loginView(HttpServletRequest req, HttpServletResponse res) { | ||
String path = execute(req, res); | ||
return new ModelAndView(new JspView(path)); | ||
public ModelAndView loginView(final HttpServletRequest req, | ||
final HttpServletResponse res) { | ||
return new ModelAndView(new JspView("/register.jsp")); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
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 org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
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.JsonView; | ||
|
||
@Controller | ||
public class UserController { | ||
|
||
private static final Logger log = LoggerFactory.getLogger(UserController.class); | ||
|
||
@RequestMapping(value = "/api/user", method = RequestMethod.GET) | ||
public ModelAndView show(final HttpServletRequest request, | ||
final HttpServletResponse response) { | ||
final String account = request.getParameter("account"); | ||
log.debug("user id : {}", account); | ||
|
||
final ModelAndView modelAndView = new ModelAndView(new JsonView()); | ||
final User user = InMemoryUserRepository.findByAccount(account) | ||
.orElseThrow(); | ||
|
||
modelAndView.addObject("user", user); | ||
return modelAndView; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,7 +14,8 @@ public ModelAndView(final View view) { | |
this.model = new HashMap<>(); | ||
} | ||
|
||
public ModelAndView addObject(final String attributeName, final Object attributeValue) { | ||
public ModelAndView addObject(final String attributeName, | ||
final Object attributeValue) { | ||
model.put(attributeName, attributeValue); | ||
return this; | ||
Comment on lines
+17
to
20
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. 빌더 패턴 👍 |
||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,7 +14,8 @@ public ForwardController(final String path) { | |
} | ||
|
||
@Override | ||
public String execute(final HttpServletRequest request, final HttpServletResponse response) { | ||
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. 이번 미션의 요구사항 3번인 Legacy MVC 제거하기 내용을 한번 확인해보면 좋을 것 같아요!
FrontController, Controller 등 불필요한 레거시 코드는 제거하면 좋을 것 같아요~ 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. 조이! 한번더 todo list를 체크해 주셔서 감사합니다! 덕분에 레거시 코드를 삭제해도 잘 되는지 확인해볼 수 있었습니다! 남겨주신 체크리스트에 체크하였습니다~! |
||
public String execute(final HttpServletRequest request, | ||
final HttpServletResponse response) { | ||
return path; | ||
} | ||
} |
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.
잘 반영 해주셨네요!👍