-
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단계] 채채 (신채원) 미션 제출합니다 #613
Changes from all 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
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,20 @@ | ||
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 { | ||
@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로 되어있군요..ㅠㅠ 수정하겠습니다~! |
||
|
||
@Override | ||
public String execute(final HttpServletRequest req, final HttpServletResponse res) { | ||
final var session = req.getSession(); | ||
@RequestMapping(value = "/logout", method = RequestMethod.GET) | ||
public ModelAndView logout(HttpServletRequest request, HttpServletResponse response) { | ||
final var session = request.getSession(); | ||
session.removeAttribute(UserSession.SESSION_KEY); | ||
return "redirect:/"; | ||
} | ||
|
||
@RequestMapping(value = "/logout", method = RequestMethod.POST) | ||
public ModelAndView logout(HttpServletRequest req, HttpServletResponse res) { | ||
String path = execute(req, res); | ||
return new ModelAndView(new JspView(path)); | ||
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. 빌더 패턴 👍 |
||
} | ||
|
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.
채채는
DispatcherServlet
과DispatcherServletInitializer
를 app 패키지에 그대로 두셨군요!mvc 패키지로 이동하는 것도 고려를 해볼 수 있을 것 같은데, 채채가
DispatcherServlet
과DispatcherServletInitializer
를 app 패키지에 두신 이유가 궁금합니다!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.
DispatcherServletInitializer가 app패키지에 의존하고있어서 따로 분리하지 못하였습니다..! 이부분에 대해서 조이는 어떻게 처리하셨나요!? 저는 이부분에대해서 전혀 감을 잡지 못하였습니다아...
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.
저도 DispatcherServletInitializer는 app 패키지에 그냥 두고 DispatcherServlet만 이동했어요!
그냥 진짜 생각해보셨는지 궁금하기도 하고, 안 해보셨으면 해보면 좋을 것 같아서 말씀드렸어요🙂