From 5fe6ab39c6d0f1bf82b4bb180392ac047ca7f127 Mon Sep 17 00:00:00 2001 From: jeonghoon Date: Mon, 25 Sep 2023 15:19:00 +0900 Subject: [PATCH 1/9] =?UTF-8?q?refactor:=20=ED=8C=A8=ED=82=A4=EC=A7=95=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/techcourse/ManualHandlerAdapter.java | 4 ++-- .../java/com/techcourse/ManualHandlerMapping.java | 2 +- mvc/build.gradle | 1 + .../web/servlet}/DispatcherServlet.java | 15 +++++++++------ .../servlet}/DispatcherServletInitializer.java | 2 +- .../springframework/web/servlet/ModelAndView.java | 2 ++ .../AnnotationHandlerAdapter.java | 5 +++-- .../web/servlet/{ => adapter}/HandlerAdapter.java | 3 ++- .../web/servlet/adapter}/HandlerAdapters.java | 4 +--- .../AnnotationHandlerMapping.java | 5 +++-- .../{ => handlermapping}/HandlerMapping.java | 2 +- .../servlet/handlermapping}/HandlerMappings.java | 3 +-- .../web/servlet/view/JsonView.java | 1 - .../springframework/web/servlet/view/JspView.java | 1 - .../web/servlet/{ => view}/View.java | 2 +- .../mvc/tobe/AnnotationHandlerMappingTest.java | 1 + 16 files changed, 29 insertions(+), 24 deletions(-) rename {app/src/main/java/com/techcourse => mvc/src/main/java/webmvc/org/springframework/web/servlet}/DispatcherServlet.java (82%) rename {app/src/main/java/com/techcourse => mvc/src/main/java/webmvc/org/springframework/web/servlet}/DispatcherServletInitializer.java (96%) rename mvc/src/main/java/webmvc/org/springframework/web/servlet/{mvc/tobe => adapter}/AnnotationHandlerAdapter.java (76%) rename mvc/src/main/java/webmvc/org/springframework/web/servlet/{ => adapter}/HandlerAdapter.java (73%) rename {app/src/main/java/com/techcourse => mvc/src/main/java/webmvc/org/springframework/web/servlet/adapter}/HandlerAdapters.java (89%) rename mvc/src/main/java/webmvc/org/springframework/web/servlet/{mvc/tobe => handlermapping}/AnnotationHandlerMapping.java (94%) rename mvc/src/main/java/webmvc/org/springframework/web/servlet/{ => handlermapping}/HandlerMapping.java (72%) rename {app/src/main/java/com/techcourse => mvc/src/main/java/webmvc/org/springframework/web/servlet/handlermapping}/HandlerMappings.java (91%) rename mvc/src/main/java/webmvc/org/springframework/web/servlet/{ => view}/View.java (83%) diff --git a/app/src/main/java/com/techcourse/ManualHandlerAdapter.java b/app/src/main/java/com/techcourse/ManualHandlerAdapter.java index fa86b16cb5..57c1741863 100644 --- a/app/src/main/java/com/techcourse/ManualHandlerAdapter.java +++ b/app/src/main/java/com/techcourse/ManualHandlerAdapter.java @@ -2,9 +2,9 @@ import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; -import webmvc.org.springframework.web.servlet.HandlerAdapter; +import webmvc.org.springframework.web.servlet.adapter.HandlerAdapter; import webmvc.org.springframework.web.servlet.ModelAndView; -import webmvc.org.springframework.web.servlet.View; +import webmvc.org.springframework.web.servlet.view.View; import webmvc.org.springframework.web.servlet.mvc.asis.Controller; import webmvc.org.springframework.web.servlet.view.JspView; diff --git a/app/src/main/java/com/techcourse/ManualHandlerMapping.java b/app/src/main/java/com/techcourse/ManualHandlerMapping.java index b1d5ed265d..1b34f3dfcf 100644 --- a/app/src/main/java/com/techcourse/ManualHandlerMapping.java +++ b/app/src/main/java/com/techcourse/ManualHandlerMapping.java @@ -8,7 +8,7 @@ import jakarta.servlet.http.HttpServletRequest; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import webmvc.org.springframework.web.servlet.HandlerMapping; +import webmvc.org.springframework.web.servlet.handlermapping.HandlerMapping; import webmvc.org.springframework.web.servlet.mvc.asis.Controller; import webmvc.org.springframework.web.servlet.mvc.asis.ForwardController; diff --git a/mvc/build.gradle b/mvc/build.gradle index 8cdd011952..e7e6237cf7 100644 --- a/mvc/build.gradle +++ b/mvc/build.gradle @@ -15,6 +15,7 @@ dependencies { implementation "javax.servlet.jsp:javax.servlet.jsp-api:2.3.3" implementation "jakarta.servlet.jsp.jstl:jakarta.servlet.jsp.jstl-api:3.0.0" implementation "jakarta.annotation:jakarta.annotation-api:2.0.0" + implementation project(path: ':app') annotationProcessor "jakarta.annotation:jakarta.annotation-api:2.0.0" implementation "org.reflections:reflections:0.10.2" diff --git a/app/src/main/java/com/techcourse/DispatcherServlet.java b/mvc/src/main/java/webmvc/org/springframework/web/servlet/DispatcherServlet.java similarity index 82% rename from app/src/main/java/com/techcourse/DispatcherServlet.java rename to mvc/src/main/java/webmvc/org/springframework/web/servlet/DispatcherServlet.java index 23ae3d20fc..1f9c71c348 100644 --- a/app/src/main/java/com/techcourse/DispatcherServlet.java +++ b/mvc/src/main/java/webmvc/org/springframework/web/servlet/DispatcherServlet.java @@ -1,4 +1,4 @@ -package com.techcourse; +package webmvc.org.springframework.web.servlet; import jakarta.servlet.ServletException; import jakarta.servlet.http.HttpServlet; @@ -6,12 +6,15 @@ import jakarta.servlet.http.HttpServletResponse; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import webmvc.org.springframework.web.servlet.HandlerAdapter; -import webmvc.org.springframework.web.servlet.ModelAndView; -import webmvc.org.springframework.web.servlet.View; -import webmvc.org.springframework.web.servlet.mvc.tobe.AnnotationHandlerAdapter; -import webmvc.org.springframework.web.servlet.mvc.tobe.AnnotationHandlerMapping; +import webmvc.org.springframework.web.servlet.adapter.HandlerAdapter; +import webmvc.org.springframework.web.servlet.adapter.HandlerAdapters; +import com.techcourse.ManualHandlerAdapter; +import webmvc.org.springframework.web.servlet.handlermapping.HandlerMappings; +import webmvc.org.springframework.web.servlet.adapter.AnnotationHandlerAdapter; +import webmvc.org.springframework.web.servlet.handlermapping.AnnotationHandlerMapping; +import com.techcourse.ManualHandlerMapping; import webmvc.org.springframework.web.servlet.view.JspView; +import webmvc.org.springframework.web.servlet.view.View; public class DispatcherServlet extends HttpServlet { diff --git a/app/src/main/java/com/techcourse/DispatcherServletInitializer.java b/mvc/src/main/java/webmvc/org/springframework/web/servlet/DispatcherServletInitializer.java similarity index 96% rename from app/src/main/java/com/techcourse/DispatcherServletInitializer.java rename to mvc/src/main/java/webmvc/org/springframework/web/servlet/DispatcherServletInitializer.java index ae8c57ae53..529dc19a8a 100644 --- a/app/src/main/java/com/techcourse/DispatcherServletInitializer.java +++ b/mvc/src/main/java/webmvc/org/springframework/web/servlet/DispatcherServletInitializer.java @@ -1,4 +1,4 @@ -package com.techcourse; +package webmvc.org.springframework.web.servlet; import jakarta.servlet.ServletContext; import jakarta.servlet.ServletRegistration; diff --git a/mvc/src/main/java/webmvc/org/springframework/web/servlet/ModelAndView.java b/mvc/src/main/java/webmvc/org/springframework/web/servlet/ModelAndView.java index ff8e24553f..8e57277a43 100644 --- a/mvc/src/main/java/webmvc/org/springframework/web/servlet/ModelAndView.java +++ b/mvc/src/main/java/webmvc/org/springframework/web/servlet/ModelAndView.java @@ -1,5 +1,7 @@ package webmvc.org.springframework.web.servlet; +import webmvc.org.springframework.web.servlet.view.View; + import java.util.Collections; import java.util.HashMap; import java.util.Map; diff --git a/mvc/src/main/java/webmvc/org/springframework/web/servlet/mvc/tobe/AnnotationHandlerAdapter.java b/mvc/src/main/java/webmvc/org/springframework/web/servlet/adapter/AnnotationHandlerAdapter.java similarity index 76% rename from mvc/src/main/java/webmvc/org/springframework/web/servlet/mvc/tobe/AnnotationHandlerAdapter.java rename to mvc/src/main/java/webmvc/org/springframework/web/servlet/adapter/AnnotationHandlerAdapter.java index ee17a3bd67..3dfb1fcdb6 100644 --- a/mvc/src/main/java/webmvc/org/springframework/web/servlet/mvc/tobe/AnnotationHandlerAdapter.java +++ b/mvc/src/main/java/webmvc/org/springframework/web/servlet/adapter/AnnotationHandlerAdapter.java @@ -1,9 +1,10 @@ -package webmvc.org.springframework.web.servlet.mvc.tobe; +package webmvc.org.springframework.web.servlet.adapter; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; -import webmvc.org.springframework.web.servlet.HandlerAdapter; +import webmvc.org.springframework.web.servlet.adapter.HandlerAdapter; import webmvc.org.springframework.web.servlet.ModelAndView; +import webmvc.org.springframework.web.servlet.mvc.tobe.HandlerExecution; public class AnnotationHandlerAdapter implements HandlerAdapter { diff --git a/mvc/src/main/java/webmvc/org/springframework/web/servlet/HandlerAdapter.java b/mvc/src/main/java/webmvc/org/springframework/web/servlet/adapter/HandlerAdapter.java similarity index 73% rename from mvc/src/main/java/webmvc/org/springframework/web/servlet/HandlerAdapter.java rename to mvc/src/main/java/webmvc/org/springframework/web/servlet/adapter/HandlerAdapter.java index 60f3684507..8ffa2041cc 100644 --- a/mvc/src/main/java/webmvc/org/springframework/web/servlet/HandlerAdapter.java +++ b/mvc/src/main/java/webmvc/org/springframework/web/servlet/adapter/HandlerAdapter.java @@ -1,7 +1,8 @@ -package webmvc.org.springframework.web.servlet; +package webmvc.org.springframework.web.servlet.adapter; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; +import webmvc.org.springframework.web.servlet.ModelAndView; public interface HandlerAdapter { diff --git a/app/src/main/java/com/techcourse/HandlerAdapters.java b/mvc/src/main/java/webmvc/org/springframework/web/servlet/adapter/HandlerAdapters.java similarity index 89% rename from app/src/main/java/com/techcourse/HandlerAdapters.java rename to mvc/src/main/java/webmvc/org/springframework/web/servlet/adapter/HandlerAdapters.java index 572375bef6..933f24f5b8 100644 --- a/app/src/main/java/com/techcourse/HandlerAdapters.java +++ b/mvc/src/main/java/webmvc/org/springframework/web/servlet/adapter/HandlerAdapters.java @@ -1,6 +1,4 @@ -package com.techcourse; - -import webmvc.org.springframework.web.servlet.HandlerAdapter; +package webmvc.org.springframework.web.servlet.adapter; import java.util.HashSet; import java.util.Set; diff --git a/mvc/src/main/java/webmvc/org/springframework/web/servlet/mvc/tobe/AnnotationHandlerMapping.java b/mvc/src/main/java/webmvc/org/springframework/web/servlet/handlermapping/AnnotationHandlerMapping.java similarity index 94% rename from mvc/src/main/java/webmvc/org/springframework/web/servlet/mvc/tobe/AnnotationHandlerMapping.java rename to mvc/src/main/java/webmvc/org/springframework/web/servlet/handlermapping/AnnotationHandlerMapping.java index 7dcd3b4fea..568cb5260f 100644 --- a/mvc/src/main/java/webmvc/org/springframework/web/servlet/mvc/tobe/AnnotationHandlerMapping.java +++ b/mvc/src/main/java/webmvc/org/springframework/web/servlet/handlermapping/AnnotationHandlerMapping.java @@ -1,4 +1,4 @@ -package webmvc.org.springframework.web.servlet.mvc.tobe; +package webmvc.org.springframework.web.servlet.handlermapping; import context.org.springframework.stereotype.Controller; import jakarta.servlet.http.HttpServletRequest; @@ -7,7 +7,8 @@ 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.HandlerMapping; +import webmvc.org.springframework.web.servlet.mvc.tobe.HandlerExecution; +import webmvc.org.springframework.web.servlet.mvc.tobe.HandlerKey; import java.lang.reflect.Method; import java.util.Arrays; diff --git a/mvc/src/main/java/webmvc/org/springframework/web/servlet/HandlerMapping.java b/mvc/src/main/java/webmvc/org/springframework/web/servlet/handlermapping/HandlerMapping.java similarity index 72% rename from mvc/src/main/java/webmvc/org/springframework/web/servlet/HandlerMapping.java rename to mvc/src/main/java/webmvc/org/springframework/web/servlet/handlermapping/HandlerMapping.java index eaee258dcd..9f63c90d98 100644 --- a/mvc/src/main/java/webmvc/org/springframework/web/servlet/HandlerMapping.java +++ b/mvc/src/main/java/webmvc/org/springframework/web/servlet/handlermapping/HandlerMapping.java @@ -1,4 +1,4 @@ -package webmvc.org.springframework.web.servlet; +package webmvc.org.springframework.web.servlet.handlermapping; import jakarta.servlet.http.HttpServletRequest; diff --git a/app/src/main/java/com/techcourse/HandlerMappings.java b/mvc/src/main/java/webmvc/org/springframework/web/servlet/handlermapping/HandlerMappings.java similarity index 91% rename from app/src/main/java/com/techcourse/HandlerMappings.java rename to mvc/src/main/java/webmvc/org/springframework/web/servlet/handlermapping/HandlerMappings.java index 0db40e8a89..c8586434ed 100644 --- a/app/src/main/java/com/techcourse/HandlerMappings.java +++ b/mvc/src/main/java/webmvc/org/springframework/web/servlet/handlermapping/HandlerMappings.java @@ -1,7 +1,6 @@ -package com.techcourse; +package webmvc.org.springframework.web.servlet.handlermapping; import jakarta.servlet.http.HttpServletRequest; -import webmvc.org.springframework.web.servlet.HandlerMapping; import java.util.HashSet; import java.util.Objects; diff --git a/mvc/src/main/java/webmvc/org/springframework/web/servlet/view/JsonView.java b/mvc/src/main/java/webmvc/org/springframework/web/servlet/view/JsonView.java index b42c3466f0..7d3dd52fdd 100644 --- a/mvc/src/main/java/webmvc/org/springframework/web/servlet/view/JsonView.java +++ b/mvc/src/main/java/webmvc/org/springframework/web/servlet/view/JsonView.java @@ -2,7 +2,6 @@ import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; -import webmvc.org.springframework.web.servlet.View; import java.util.Map; diff --git a/mvc/src/main/java/webmvc/org/springframework/web/servlet/view/JspView.java b/mvc/src/main/java/webmvc/org/springframework/web/servlet/view/JspView.java index a86514497b..3760d60f03 100644 --- a/mvc/src/main/java/webmvc/org/springframework/web/servlet/view/JspView.java +++ b/mvc/src/main/java/webmvc/org/springframework/web/servlet/view/JspView.java @@ -4,7 +4,6 @@ import jakarta.servlet.http.HttpServletResponse; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import webmvc.org.springframework.web.servlet.View; import java.util.Map; diff --git a/mvc/src/main/java/webmvc/org/springframework/web/servlet/View.java b/mvc/src/main/java/webmvc/org/springframework/web/servlet/view/View.java similarity index 83% rename from mvc/src/main/java/webmvc/org/springframework/web/servlet/View.java rename to mvc/src/main/java/webmvc/org/springframework/web/servlet/view/View.java index bcb9313556..7e44b562a9 100644 --- a/mvc/src/main/java/webmvc/org/springframework/web/servlet/View.java +++ b/mvc/src/main/java/webmvc/org/springframework/web/servlet/view/View.java @@ -1,4 +1,4 @@ -package webmvc.org.springframework.web.servlet; +package webmvc.org.springframework.web.servlet.view; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; diff --git a/mvc/src/test/java/webmvc/org/springframework/web/servlet/mvc/tobe/AnnotationHandlerMappingTest.java b/mvc/src/test/java/webmvc/org/springframework/web/servlet/mvc/tobe/AnnotationHandlerMappingTest.java index dcec215a3f..c9243e0d0a 100644 --- a/mvc/src/test/java/webmvc/org/springframework/web/servlet/mvc/tobe/AnnotationHandlerMappingTest.java +++ b/mvc/src/test/java/webmvc/org/springframework/web/servlet/mvc/tobe/AnnotationHandlerMappingTest.java @@ -4,6 +4,7 @@ import jakarta.servlet.http.HttpServletResponse; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import webmvc.org.springframework.web.servlet.handlermapping.AnnotationHandlerMapping; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; From 43e0a2ed0993090a286a86d5f653076f5c146dc0 Mon Sep 17 00:00:00 2001 From: jeonghoon Date: Mon, 25 Sep 2023 15:44:05 +0900 Subject: [PATCH 2/9] =?UTF-8?q?refactor:=20view=20=EC=97=AD=ED=95=A0=20?= =?UTF-8?q?=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../web/servlet/DispatcherServlet.java | 14 +------------- .../springframework/web/servlet/view/JspView.java | 13 +++++++------ 2 files changed, 8 insertions(+), 19 deletions(-) diff --git a/mvc/src/main/java/webmvc/org/springframework/web/servlet/DispatcherServlet.java b/mvc/src/main/java/webmvc/org/springframework/web/servlet/DispatcherServlet.java index 1f9c71c348..ed60d251ae 100644 --- a/mvc/src/main/java/webmvc/org/springframework/web/servlet/DispatcherServlet.java +++ b/mvc/src/main/java/webmvc/org/springframework/web/servlet/DispatcherServlet.java @@ -57,22 +57,10 @@ protected void service(final HttpServletRequest req, final HttpServletResponse r final HandlerAdapter handlerAdapter = handlerAdapters.getHandlerAdapter(handler); final ModelAndView modelAndView = handlerAdapter.handle(req, res, handler); final View view = modelAndView.getView(); - if (view instanceof JspView) { - move(((JspView) view).getViewName(), req, res); - } + view.render(modelAndView.getModel(), req, res); } catch (Throwable e) { log.error("Exception : {}", e.getMessage(), e); throw new ServletException(e.getMessage()); } } - - private void move(final String viewName, final HttpServletRequest request, final HttpServletResponse response) throws Exception { - if (viewName.startsWith(JspView.REDIRECT_PREFIX)) { - response.sendRedirect(viewName.substring(JspView.REDIRECT_PREFIX.length())); - return; - } - - final var requestDispatcher = request.getRequestDispatcher(viewName); - requestDispatcher.forward(request, response); - } } diff --git a/mvc/src/main/java/webmvc/org/springframework/web/servlet/view/JspView.java b/mvc/src/main/java/webmvc/org/springframework/web/servlet/view/JspView.java index 3760d60f03..853d83d022 100644 --- a/mvc/src/main/java/webmvc/org/springframework/web/servlet/view/JspView.java +++ b/mvc/src/main/java/webmvc/org/springframework/web/servlet/view/JspView.java @@ -1,5 +1,6 @@ package webmvc.org.springframework.web.servlet.view; +import jakarta.servlet.RequestDispatcher; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; import org.slf4j.Logger; @@ -21,17 +22,17 @@ public JspView(final String viewName) { @Override public void render(final Map model, final HttpServletRequest request, final HttpServletResponse response) throws Exception { - // todo - model.keySet().forEach(key -> { log.debug("attribute name : {}, value : {}", key, model.get(key)); request.setAttribute(key, model.get(key)); }); - // todo - } + if (viewName.startsWith(JspView.REDIRECT_PREFIX)) { + response.sendRedirect(viewName.substring(JspView.REDIRECT_PREFIX.length())); + return; + } - public String getViewName() { - return viewName; + final RequestDispatcher requestDispatcher = request.getRequestDispatcher(viewName); + requestDispatcher.forward(request, response); } } From b5f2211a12b5f0fe41f94294f7c59f4dd02a37c0 Mon Sep 17 00:00:00 2001 From: jeonghoon Date: Mon, 25 Sep 2023 16:22:21 +0900 Subject: [PATCH 3/9] =?UTF-8?q?feat:=20JsonView=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../web/servlet/DispatcherServlet.java | 1 - .../springframework/web/servlet/view/JsonView.java | 14 ++++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/mvc/src/main/java/webmvc/org/springframework/web/servlet/DispatcherServlet.java b/mvc/src/main/java/webmvc/org/springframework/web/servlet/DispatcherServlet.java index ed60d251ae..b9330fbd59 100644 --- a/mvc/src/main/java/webmvc/org/springframework/web/servlet/DispatcherServlet.java +++ b/mvc/src/main/java/webmvc/org/springframework/web/servlet/DispatcherServlet.java @@ -13,7 +13,6 @@ import webmvc.org.springframework.web.servlet.adapter.AnnotationHandlerAdapter; import webmvc.org.springframework.web.servlet.handlermapping.AnnotationHandlerMapping; import com.techcourse.ManualHandlerMapping; -import webmvc.org.springframework.web.servlet.view.JspView; import webmvc.org.springframework.web.servlet.view.View; public class DispatcherServlet extends HttpServlet { diff --git a/mvc/src/main/java/webmvc/org/springframework/web/servlet/view/JsonView.java b/mvc/src/main/java/webmvc/org/springframework/web/servlet/view/JsonView.java index 7d3dd52fdd..796c2c3940 100644 --- a/mvc/src/main/java/webmvc/org/springframework/web/servlet/view/JsonView.java +++ b/mvc/src/main/java/webmvc/org/springframework/web/servlet/view/JsonView.java @@ -1,7 +1,9 @@ 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 java.util.Map; @@ -9,5 +11,17 @@ public class JsonView implements View { @Override public void render(final Map model, final HttpServletRequest request, HttpServletResponse response) throws Exception { + final ObjectMapper objectMapper = new ObjectMapper(); + final Object modelValue = getModelValue(model); + + response.setContentType(MediaType.APPLICATION_JSON_UTF8_VALUE); + response.getWriter().write(objectMapper.writeValueAsString(modelValue)); + } + + private Object getModelValue(final Map model) { + if (model.size() == 1) { + return model.values().iterator().next(); + } + return model; } } From 31b393be50ee7cb4540099d219d9aaa30a734daa Mon Sep 17 00:00:00 2001 From: jeonghoon Date: Mon, 25 Sep 2023 16:24:14 +0900 Subject: [PATCH 4/9] =?UTF-8?q?feat:=20UserController=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../techcourse/controller/UserController.java | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 app/src/main/java/com/techcourse/controller/UserController.java diff --git a/app/src/main/java/com/techcourse/controller/UserController.java b/app/src/main/java/com/techcourse/controller/UserController.java new file mode 100644 index 0000000000..c1361f487b --- /dev/null +++ b/app/src/main/java/com/techcourse/controller/UserController.java @@ -0,0 +1,32 @@ +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(HttpServletRequest request, 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; + } +} From 1450f4c2bb361a0f702643847ae6e388f8f40339 Mon Sep 17 00:00:00 2001 From: jeonghoon Date: Mon, 25 Sep 2023 17:00:49 +0900 Subject: [PATCH 5/9] =?UTF-8?q?feat:=20=EB=A0=88=EA=B1=B0=EC=8B=9C=20contr?= =?UTF-8?q?oller=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/techcourse}/DispatcherServlet.java | 7 +-- .../DispatcherServletInitializer.java | 2 +- .../com/techcourse/ManualHandlerAdapter.java | 25 ----------- .../com/techcourse/ManualHandlerMapping.java | 44 ------------------- .../controller/DazzleController.java | 4 +- .../controller/LoginController.java | 23 ++++++---- .../controller/LoginViewController.java | 17 ++++--- .../controller/LogoutController.java | 15 ++++--- .../controller/RegisterController.java | 15 ++++--- .../controller/RegisterViewController.java | 15 ++++--- .../techcourse/controller/UserController.java | 1 - mvc/build.gradle | 1 - .../web/servlet/mvc/asis/Controller.java | 8 ---- .../servlet/mvc/asis/ForwardController.java | 20 --------- 14 files changed, 60 insertions(+), 137 deletions(-) rename {mvc/src/main/java/webmvc/org/springframework/web/servlet => app/src/main/java/com/techcourse}/DispatcherServlet.java (89%) rename {mvc/src/main/java/webmvc/org/springframework/web/servlet => app/src/main/java/com/techcourse}/DispatcherServletInitializer.java (96%) delete mode 100644 app/src/main/java/com/techcourse/ManualHandlerAdapter.java delete mode 100644 app/src/main/java/com/techcourse/ManualHandlerMapping.java delete mode 100644 mvc/src/main/java/webmvc/org/springframework/web/servlet/mvc/asis/Controller.java delete mode 100644 mvc/src/main/java/webmvc/org/springframework/web/servlet/mvc/asis/ForwardController.java diff --git a/mvc/src/main/java/webmvc/org/springframework/web/servlet/DispatcherServlet.java b/app/src/main/java/com/techcourse/DispatcherServlet.java similarity index 89% rename from mvc/src/main/java/webmvc/org/springframework/web/servlet/DispatcherServlet.java rename to app/src/main/java/com/techcourse/DispatcherServlet.java index b9330fbd59..c91aa86d83 100644 --- a/mvc/src/main/java/webmvc/org/springframework/web/servlet/DispatcherServlet.java +++ b/app/src/main/java/com/techcourse/DispatcherServlet.java @@ -1,4 +1,4 @@ -package webmvc.org.springframework.web.servlet; +package com.techcourse; import jakarta.servlet.ServletException; import jakarta.servlet.http.HttpServlet; @@ -6,13 +6,12 @@ import jakarta.servlet.http.HttpServletResponse; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import webmvc.org.springframework.web.servlet.ModelAndView; import webmvc.org.springframework.web.servlet.adapter.HandlerAdapter; import webmvc.org.springframework.web.servlet.adapter.HandlerAdapters; -import com.techcourse.ManualHandlerAdapter; import webmvc.org.springframework.web.servlet.handlermapping.HandlerMappings; import webmvc.org.springframework.web.servlet.adapter.AnnotationHandlerAdapter; import webmvc.org.springframework.web.servlet.handlermapping.AnnotationHandlerMapping; -import com.techcourse.ManualHandlerMapping; import webmvc.org.springframework.web.servlet.view.View; public class DispatcherServlet extends HttpServlet { @@ -34,14 +33,12 @@ public void init() { private void initHandlerMappings() { final HandlerMappings handlerMappings = new HandlerMappings(); - handlerMappings.addHandlerMapping(new ManualHandlerMapping()); handlerMappings.addHandlerMapping(new AnnotationHandlerMapping()); this.handlerMappings = handlerMappings; } private void initHandlerAdapter() { final HandlerAdapters handlerAdapters = new HandlerAdapters(); - handlerAdapters.addHandlerAdapter(new ManualHandlerAdapter()); handlerAdapters.addHandlerAdapter(new AnnotationHandlerAdapter()); this.handlerAdapters = handlerAdapters; } diff --git a/mvc/src/main/java/webmvc/org/springframework/web/servlet/DispatcherServletInitializer.java b/app/src/main/java/com/techcourse/DispatcherServletInitializer.java similarity index 96% rename from mvc/src/main/java/webmvc/org/springframework/web/servlet/DispatcherServletInitializer.java rename to app/src/main/java/com/techcourse/DispatcherServletInitializer.java index 529dc19a8a..ae8c57ae53 100644 --- a/mvc/src/main/java/webmvc/org/springframework/web/servlet/DispatcherServletInitializer.java +++ b/app/src/main/java/com/techcourse/DispatcherServletInitializer.java @@ -1,4 +1,4 @@ -package webmvc.org.springframework.web.servlet; +package com.techcourse; import jakarta.servlet.ServletContext; import jakarta.servlet.ServletRegistration; diff --git a/app/src/main/java/com/techcourse/ManualHandlerAdapter.java b/app/src/main/java/com/techcourse/ManualHandlerAdapter.java deleted file mode 100644 index 57c1741863..0000000000 --- a/app/src/main/java/com/techcourse/ManualHandlerAdapter.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.techcourse; - -import jakarta.servlet.http.HttpServletRequest; -import jakarta.servlet.http.HttpServletResponse; -import webmvc.org.springframework.web.servlet.adapter.HandlerAdapter; -import webmvc.org.springframework.web.servlet.ModelAndView; -import webmvc.org.springframework.web.servlet.view.View; -import webmvc.org.springframework.web.servlet.mvc.asis.Controller; -import webmvc.org.springframework.web.servlet.view.JspView; - -public class ManualHandlerAdapter implements HandlerAdapter { - - @Override - public boolean supports(final Object handler) { - return handler instanceof Controller; - } - - @Override - public ModelAndView handle(final HttpServletRequest req, final HttpServletResponse res, final Object handler) throws Exception { - final Controller controller = (Controller) handler; - final String viewName = controller.execute(req, res); - final View view = new JspView(viewName); - return new ModelAndView(view); - } -} diff --git a/app/src/main/java/com/techcourse/ManualHandlerMapping.java b/app/src/main/java/com/techcourse/ManualHandlerMapping.java deleted file mode 100644 index 1b34f3dfcf..0000000000 --- a/app/src/main/java/com/techcourse/ManualHandlerMapping.java +++ /dev/null @@ -1,44 +0,0 @@ -package com.techcourse; - -import com.techcourse.controller.LoginController; -import com.techcourse.controller.LoginViewController; -import com.techcourse.controller.LogoutController; -import com.techcourse.controller.RegisterController; -import com.techcourse.controller.RegisterViewController; -import jakarta.servlet.http.HttpServletRequest; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import webmvc.org.springframework.web.servlet.handlermapping.HandlerMapping; -import webmvc.org.springframework.web.servlet.mvc.asis.Controller; -import webmvc.org.springframework.web.servlet.mvc.asis.ForwardController; - -import java.util.HashMap; -import java.util.Map; - -public class ManualHandlerMapping implements HandlerMapping { - - private static final Logger log = LoggerFactory.getLogger(ManualHandlerMapping.class); - - private static final Map controllers = new HashMap<>(); - - @Override - public void initialize() { - controllers.put("/", new ForwardController("/index.jsp")); - controllers.put("/login", new LoginController()); - controllers.put("/login/view", new LoginViewController()); - controllers.put("/logout", new LogoutController()); - controllers.put("/register/view", new RegisterViewController()); - controllers.put("/register", new RegisterController()); - - log.info("Initialized Handler Mapping!"); - controllers.keySet() - .forEach(path -> log.info("Path : {}, Controller : {}", path, controllers.get(path).getClass())); - } - - @Override - public Controller getHandler(final HttpServletRequest req) { - final String uri = req.getRequestURI(); - log.debug("Request Mapping Uri : {}", uri); - return controllers.get(uri); - } -} diff --git a/app/src/main/java/com/techcourse/controller/DazzleController.java b/app/src/main/java/com/techcourse/controller/DazzleController.java index a51628ba26..e8492168f0 100644 --- a/app/src/main/java/com/techcourse/controller/DazzleController.java +++ b/app/src/main/java/com/techcourse/controller/DazzleController.java @@ -11,8 +11,8 @@ @Controller public class DazzleController { - @RequestMapping(value = "/dazzle", method = RequestMethod.GET) + @RequestMapping(value = "/", method = RequestMethod.GET) public ModelAndView showMyDazzle(final HttpServletRequest req, final HttpServletResponse res) { - return new ModelAndView(new JspView("404.jsp")); + return new ModelAndView(new JspView("index.jsp")); } } diff --git a/app/src/main/java/com/techcourse/controller/LoginController.java b/app/src/main/java/com/techcourse/controller/LoginController.java index 0428fe109e..b9b3ffaa79 100644 --- a/app/src/main/java/com/techcourse/controller/LoginController.java +++ b/app/src/main/java/com/techcourse/controller/LoginController.java @@ -2,20 +2,25 @@ 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 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 org.slf4j.Logger; import org.slf4j.LoggerFactory; +import webmvc.org.springframework.web.servlet.ModelAndView; +import webmvc.org.springframework.web.servlet.view.JspView; -public class LoginController implements Controller { +@Controller +public class LoginController { private static final Logger log = LoggerFactory.getLogger(LoginController.class); - @Override - public String execute(final HttpServletRequest req, final HttpServletResponse res) throws Exception { + @RequestMapping(value = "/login", method = RequestMethod.POST) + public ModelAndView execute(final HttpServletRequest req, final HttpServletResponse res) throws Exception { if (UserSession.isLoggedIn(req.getSession())) { - return "redirect:/index.jsp"; + return new ModelAndView(new JspView("redirect:/index.jsp")); } return InMemoryUserRepository.findByAccount(req.getParameter("account")) @@ -23,15 +28,15 @@ public String execute(final HttpServletRequest req, final HttpServletResponse re log.info("User : {}", user); return login(req, user); }) - .orElse("redirect:/401.jsp"); + .orElse(new ModelAndView(new JspView("redirect:/401.jsp"))); } - private String login(final HttpServletRequest request, final User user) { + private ModelAndView login(final HttpServletRequest request, final User user) { if (user.checkPassword(request.getParameter("password"))) { final var session = request.getSession(); session.setAttribute(UserSession.SESSION_KEY, user); - return "redirect:/index.jsp"; + return new ModelAndView(new JspView("redirect:/index.jsp")); } - return "redirect:/401.jsp"; + return new ModelAndView(new JspView("redirect:/401.jsp")); } } diff --git a/app/src/main/java/com/techcourse/controller/LoginViewController.java b/app/src/main/java/com/techcourse/controller/LoginViewController.java index 86ec26cdce..b46df08351 100644 --- a/app/src/main/java/com/techcourse/controller/LoginViewController.java +++ b/app/src/main/java/com/techcourse/controller/LoginViewController.java @@ -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 execute(final HttpServletRequest req, final HttpServletResponse res) throws Exception { return UserSession.getUserFrom(req.getSession()) .map(user -> { log.info("logged in {}", user.getAccount()); - return "redirect:/index.jsp"; + return new ModelAndView(new JspView("/index.jsp")); }) - .orElse("/login.jsp"); + .orElse(new ModelAndView(new JspView("/login.jsp"))); } } diff --git a/app/src/main/java/com/techcourse/controller/LogoutController.java b/app/src/main/java/com/techcourse/controller/LogoutController.java index 4642fd9450..5aeed77254 100644 --- a/app/src/main/java/com/techcourse/controller/LogoutController.java +++ b/app/src/main/java/com/techcourse/controller/LogoutController.java @@ -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.POST) + public ModelAndView execute(final HttpServletRequest req, final HttpServletResponse res) throws Exception { final var session = req.getSession(); session.removeAttribute(UserSession.SESSION_KEY); - return "redirect:/"; + return new ModelAndView(new JspView("redirect:/")); } } diff --git a/app/src/main/java/com/techcourse/controller/RegisterController.java b/app/src/main/java/com/techcourse/controller/RegisterController.java index da62e5e8e9..375122932f 100644 --- a/app/src/main/java/com/techcourse/controller/RegisterController.java +++ b/app/src/main/java/com/techcourse/controller/RegisterController.java @@ -2,20 +2,25 @@ 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 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 RegisterController implements Controller { +@Controller +public class RegisterController { - @Override - public String execute(final HttpServletRequest req, final HttpServletResponse res) throws Exception { + @RequestMapping(value = "/register", method = RequestMethod.POST) + public ModelAndView execute(final HttpServletRequest req, final HttpServletResponse res) throws Exception { final var user = new User(2, req.getParameter("account"), req.getParameter("password"), req.getParameter("email")); InMemoryUserRepository.save(user); - return "redirect:/index.jsp"; + return new ModelAndView(new JspView("redirect:/index.jsp")); } } diff --git a/app/src/main/java/com/techcourse/controller/RegisterViewController.java b/app/src/main/java/com/techcourse/controller/RegisterViewController.java index 136962136d..dd571ba10f 100644 --- a/app/src/main/java/com/techcourse/controller/RegisterViewController.java +++ b/app/src/main/java/com/techcourse/controller/RegisterViewController.java @@ -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 execute(final HttpServletRequest req, final HttpServletResponse res) throws Exception { + return new ModelAndView(new JspView("/register.jsp")); } } diff --git a/app/src/main/java/com/techcourse/controller/UserController.java b/app/src/main/java/com/techcourse/controller/UserController.java index c1361f487b..a88d654525 100644 --- a/app/src/main/java/com/techcourse/controller/UserController.java +++ b/app/src/main/java/com/techcourse/controller/UserController.java @@ -25,7 +25,6 @@ public ModelAndView show(HttpServletRequest request, HttpServletResponse respons final ModelAndView modelAndView = new ModelAndView(new JsonView()); final User user = InMemoryUserRepository.findByAccount(account) .orElseThrow(); - modelAndView.addObject("user", user); return modelAndView; } diff --git a/mvc/build.gradle b/mvc/build.gradle index e7e6237cf7..8cdd011952 100644 --- a/mvc/build.gradle +++ b/mvc/build.gradle @@ -15,7 +15,6 @@ dependencies { implementation "javax.servlet.jsp:javax.servlet.jsp-api:2.3.3" implementation "jakarta.servlet.jsp.jstl:jakarta.servlet.jsp.jstl-api:3.0.0" implementation "jakarta.annotation:jakarta.annotation-api:2.0.0" - implementation project(path: ':app') annotationProcessor "jakarta.annotation:jakarta.annotation-api:2.0.0" implementation "org.reflections:reflections:0.10.2" diff --git a/mvc/src/main/java/webmvc/org/springframework/web/servlet/mvc/asis/Controller.java b/mvc/src/main/java/webmvc/org/springframework/web/servlet/mvc/asis/Controller.java deleted file mode 100644 index bdd1fde780..0000000000 --- a/mvc/src/main/java/webmvc/org/springframework/web/servlet/mvc/asis/Controller.java +++ /dev/null @@ -1,8 +0,0 @@ -package webmvc.org.springframework.web.servlet.mvc.asis; - -import jakarta.servlet.http.HttpServletRequest; -import jakarta.servlet.http.HttpServletResponse; - -public interface Controller { - String execute(final HttpServletRequest req, final HttpServletResponse res) throws Exception; -} diff --git a/mvc/src/main/java/webmvc/org/springframework/web/servlet/mvc/asis/ForwardController.java b/mvc/src/main/java/webmvc/org/springframework/web/servlet/mvc/asis/ForwardController.java deleted file mode 100644 index cd8f1ef371..0000000000 --- a/mvc/src/main/java/webmvc/org/springframework/web/servlet/mvc/asis/ForwardController.java +++ /dev/null @@ -1,20 +0,0 @@ -package webmvc.org.springframework.web.servlet.mvc.asis; - -import jakarta.servlet.http.HttpServletRequest; -import jakarta.servlet.http.HttpServletResponse; - -import java.util.Objects; - -public class ForwardController implements Controller { - - private final String path; - - public ForwardController(final String path) { - this.path = Objects.requireNonNull(path); - } - - @Override - public String execute(final HttpServletRequest request, final HttpServletResponse response) { - return path; - } -} From e829dcd1491b1da9c3f961379a4355e2b541cd0d Mon Sep 17 00:00:00 2001 From: jeonghoon Date: Mon, 25 Sep 2023 17:02:28 +0900 Subject: [PATCH 6/9] =?UTF-8?q?refactor:=20dispatcherServlet=20=ED=8C=A8?= =?UTF-8?q?=ED=82=A4=EC=A7=80=20=EC=9D=B4=EB=8F=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/com/techcourse/DispatcherServletInitializer.java | 1 + .../org/springframework/web/servlet}/DispatcherServlet.java | 3 +-- 2 files changed, 2 insertions(+), 2 deletions(-) rename {app/src/main/java/com/techcourse => mvc/src/main/java/webmvc/org/springframework/web/servlet}/DispatcherServlet.java (96%) diff --git a/app/src/main/java/com/techcourse/DispatcherServletInitializer.java b/app/src/main/java/com/techcourse/DispatcherServletInitializer.java index ae8c57ae53..acc7348242 100644 --- a/app/src/main/java/com/techcourse/DispatcherServletInitializer.java +++ b/app/src/main/java/com/techcourse/DispatcherServletInitializer.java @@ -5,6 +5,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import web.org.springframework.web.WebApplicationInitializer; +import webmvc.org.springframework.web.servlet.DispatcherServlet; /** * Base class for {@link WebApplicationInitializer} diff --git a/app/src/main/java/com/techcourse/DispatcherServlet.java b/mvc/src/main/java/webmvc/org/springframework/web/servlet/DispatcherServlet.java similarity index 96% rename from app/src/main/java/com/techcourse/DispatcherServlet.java rename to mvc/src/main/java/webmvc/org/springframework/web/servlet/DispatcherServlet.java index c91aa86d83..ef5b9123e2 100644 --- a/app/src/main/java/com/techcourse/DispatcherServlet.java +++ b/mvc/src/main/java/webmvc/org/springframework/web/servlet/DispatcherServlet.java @@ -1,4 +1,4 @@ -package com.techcourse; +package webmvc.org.springframework.web.servlet; import jakarta.servlet.ServletException; import jakarta.servlet.http.HttpServlet; @@ -6,7 +6,6 @@ import jakarta.servlet.http.HttpServletResponse; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import webmvc.org.springframework.web.servlet.ModelAndView; import webmvc.org.springframework.web.servlet.adapter.HandlerAdapter; import webmvc.org.springframework.web.servlet.adapter.HandlerAdapters; import webmvc.org.springframework.web.servlet.handlermapping.HandlerMappings; From f384e2528d3ef2c9fc56bd81708daa316862e49c Mon Sep 17 00:00:00 2001 From: jeonghoon Date: Mon, 25 Sep 2023 17:11:02 +0900 Subject: [PATCH 7/9] =?UTF-8?q?refactor:=20User=EC=97=90=20getter=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/com/techcourse/domain/User.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/app/src/main/java/com/techcourse/domain/User.java b/app/src/main/java/com/techcourse/domain/User.java index beb0919b7e..fd7d45dde8 100644 --- a/app/src/main/java/com/techcourse/domain/User.java +++ b/app/src/main/java/com/techcourse/domain/User.java @@ -22,6 +22,18 @@ public String getAccount() { return account; } + public long getId() { + return id; + } + + public String getPassword() { + return password; + } + + public String getEmail() { + return email; + } + @Override public String toString() { return "User{" + From 92a75c54147eab0b7dbb9ae81f0dd9b5a5d170a9 Mon Sep 17 00:00:00 2001 From: jeonghoon Date: Mon, 25 Sep 2023 19:33:56 +0900 Subject: [PATCH 8/9] =?UTF-8?q?refactor:=20=EB=A1=9C=EA=B7=B8=EC=95=84?= =?UTF-8?q?=EC=9B=83=20=EC=98=A4=EB=A5=98=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/com/techcourse/controller/LogoutController.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/com/techcourse/controller/LogoutController.java b/app/src/main/java/com/techcourse/controller/LogoutController.java index 5aeed77254..7e9aa9d791 100644 --- a/app/src/main/java/com/techcourse/controller/LogoutController.java +++ b/app/src/main/java/com/techcourse/controller/LogoutController.java @@ -11,7 +11,7 @@ @Controller public class LogoutController { - @RequestMapping(value = "/logout", method = RequestMethod.POST) + @RequestMapping(value = "/logout", method = RequestMethod.GET) public ModelAndView execute(final HttpServletRequest req, final HttpServletResponse res) throws Exception { final var session = req.getSession(); session.removeAttribute(UserSession.SESSION_KEY); From 2cc9a451d7f19831b298bd3edb6e07b2426c3ec4 Mon Sep 17 00:00:00 2001 From: jeonghoon Date: Tue, 26 Sep 2023 10:37:36 +0900 Subject: [PATCH 9/9] =?UTF-8?q?refactor:=20ObjectMapper=EB=A5=BC=20JsonVie?= =?UTF-8?q?w=20=ED=95=84=EB=93=9C=EB=A1=9C=20=EB=91=90=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../webmvc/org/springframework/web/servlet/view/JsonView.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mvc/src/main/java/webmvc/org/springframework/web/servlet/view/JsonView.java b/mvc/src/main/java/webmvc/org/springframework/web/servlet/view/JsonView.java index 796c2c3940..dcada7d812 100644 --- a/mvc/src/main/java/webmvc/org/springframework/web/servlet/view/JsonView.java +++ b/mvc/src/main/java/webmvc/org/springframework/web/servlet/view/JsonView.java @@ -9,9 +9,10 @@ public class JsonView implements View { + private final ObjectMapper objectMapper = new ObjectMapper(); + @Override public void render(final Map model, final HttpServletRequest request, HttpServletResponse response) throws Exception { - final ObjectMapper objectMapper = new ObjectMapper(); final Object modelValue = getModelValue(model); response.setContentType(MediaType.APPLICATION_JSON_UTF8_VALUE);