-
Notifications
You must be signed in to change notification settings - Fork 305
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[MVC 구현 - 3단계] 스플릿-박상현 미션 제출합니다. (#562)
- Loading branch information
1 parent
25abc90
commit 3b8d02c
Showing
34 changed files
with
502 additions
and
292 deletions.
There are no files selected for viewing
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
47 changes: 0 additions & 47 deletions
47
app/src/main/java/com/techcourse/ManualHandlerMapping.java
This file was deleted.
Oops, something went wrong.
33 changes: 33 additions & 0 deletions
33
app/src/main/java/com/techcourse/NotFoundResponseHandler.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,33 @@ | ||
package com.techcourse; | ||
|
||
import jakarta.servlet.http.HttpServletRequest; | ||
import jakarta.servlet.http.HttpServletResponse; | ||
import java.util.Objects; | ||
import webmvc.org.springframework.web.servlet.ModelAndView; | ||
import webmvc.org.springframework.web.servlet.mvc.tobe.exceptionhandlermapping.ExceptionHandler; | ||
import webmvc.org.springframework.web.servlet.view.JspView; | ||
|
||
public class NotFoundResponseHandler implements ExceptionHandler { | ||
|
||
private static final int NOT_FOUND_STATUS_CODE = 404; | ||
|
||
private String viewName; | ||
|
||
@Override | ||
public void initialize() { | ||
this.viewName = "404.jsp"; | ||
} | ||
|
||
@Override | ||
public boolean isHandleable(final HttpServletRequest request, final HttpServletResponse response) { | ||
return response.getStatus() == NOT_FOUND_STATUS_CODE; | ||
} | ||
|
||
@Override | ||
public ModelAndView handle(final HttpServletRequest request) { | ||
if (Objects.nonNull(viewName)) { | ||
return new ModelAndView(new JspView(viewName)); | ||
} | ||
throw new UnsupportedOperationException(); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
app/src/main/java/com/techcourse/controller/HomeController.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,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.view.JspView; | ||
|
||
@Controller | ||
public class HomeController { | ||
|
||
private static final JspView INDEX_PAGE_VIEW = new JspView("/index.jsp"); | ||
|
||
@RequestMapping(value = "/", method = RequestMethod.GET) | ||
public ModelAndView home(final HttpServletRequest request, final HttpServletResponse response) { | ||
return new ModelAndView(INDEX_PAGE_VIEW); | ||
} | ||
} |
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
27 changes: 18 additions & 9 deletions
27
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,31 @@ | ||
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; | ||
import webmvc.org.springframework.web.servlet.view.JspView; | ||
|
||
public class LoginViewController implements Controller { | ||
@Controller | ||
public class LoginViewController { | ||
|
||
private static final View LOGIN_PAGE_VIEW = new JspView("redirect:/login.jsp"); | ||
private static final JspView REDIRECT_INDEX_PAGE_VIEW = new JspView("redirect:/index.jsp"); | ||
|
||
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 showLoginPage(final HttpServletRequest req, final HttpServletResponse res) { | ||
return UserSession.getUserFrom(req.getSession()) | ||
.map(user -> { | ||
log.info("logged in {}", user.getAccount()); | ||
return "redirect:/index.jsp"; | ||
}) | ||
.orElse("/login.jsp"); | ||
.map(user -> { | ||
log.info("logged in {}", user.getAccount()); | ||
return new ModelAndView(REDIRECT_INDEX_PAGE_VIEW); | ||
}) | ||
.orElse(new ModelAndView(LOGIN_PAGE_VIEW)); | ||
} | ||
} |
17 changes: 12 additions & 5 deletions
17
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,22 @@ | ||
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 { | ||
private static final JspView REDIRECT_HOME_PAGE_VIEW = new JspView("redirect:/"); | ||
|
||
@RequestMapping(value = "/logout", method = RequestMethod.POST) | ||
public ModelAndView logout(final HttpServletRequest req, final HttpServletResponse res) { | ||
final var session = req.getSession(); | ||
session.removeAttribute(UserSession.SESSION_KEY); | ||
return "redirect:/"; | ||
return new ModelAndView(REDIRECT_HOME_PAGE_VIEW); | ||
} | ||
} |
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: 12 additions & 5 deletions
17
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,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 RegisterViewController implements Controller { | ||
@Controller | ||
public class RegisterViewController { | ||
|
||
@Override | ||
public String execute(final HttpServletRequest req, final HttpServletResponse res) throws Exception { | ||
return "/register.jsp"; | ||
private static final JspView REGISTER_PAGE_VIEW = new JspView("/register.jsp"); | ||
|
||
@RequestMapping(value = "/register/view", method = RequestMethod.GET) | ||
public ModelAndView showRegisterPage(final HttpServletRequest req, final HttpServletResponse res) { | ||
return new ModelAndView(REGISTER_PAGE_VIEW); | ||
} | ||
} |
Oops, something went wrong.