From aadb056fb0697bf93a25bbe85b2ce114d2ab54a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=83=81=EB=8C=80?= Date: Thu, 25 Nov 2021 13:13:44 +0900 Subject: [PATCH] =?UTF-8?q?#4=20REST=20API=20=EA=B0=9C=EB=B0=9C=ED=99=98?= =?UTF-8?q?=EA=B2=BD=20=EC=84=A4=EC=A0=95=20#4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 5 ++++ .../common/AuthenticationInterceptor.java | 6 ++++- .../hconnect/controller/SampleController.java | 20 --------------- .../kr/co/hconnect/rest/SampleController.java | 18 +++++++++++++ src/main/java/kr/co/hconnect/vo/SampleVO.java | 25 +++++++++++++++++++ .../resources/config/dispatcher-servlet.xml | 2 ++ src/main/webapp/WEB-INF/web.xml | 13 +++++++++- 7 files changed, 67 insertions(+), 22 deletions(-) delete mode 100644 src/main/java/kr/co/hconnect/controller/SampleController.java create mode 100644 src/main/java/kr/co/hconnect/rest/SampleController.java create mode 100644 src/main/java/kr/co/hconnect/vo/SampleVO.java diff --git a/pom.xml b/pom.xml index 8dd60cf..f07eee3 100644 --- a/pom.xml +++ b/pom.xml @@ -128,6 +128,11 @@ jackson-annotations 2.9.9 + + com.fasterxml.jackson.datatype + jackson-datatype-jsr310 + 2.9.9 + diff --git a/src/main/java/kr/co/hconnect/common/AuthenticationInterceptor.java b/src/main/java/kr/co/hconnect/common/AuthenticationInterceptor.java index 2af2865..71bef35 100644 --- a/src/main/java/kr/co/hconnect/common/AuthenticationInterceptor.java +++ b/src/main/java/kr/co/hconnect/common/AuthenticationInterceptor.java @@ -51,10 +51,14 @@ public void setPermitUrls(String... permitUrls) { public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { // 인증체크 제외 URL인 경우 String uri = request.getRequestURI(); - LOGGER.info("URI: {}", uri); + LOGGER.info("Request URI: {}", uri); if (this.permitUrls.contains(uri)) return true; + // REST API 대응 URL은 인증체크에서 제외 + if (uri.startsWith("/api/")) + return true; + // 로그인여부 확인. 로그인 사용자가 아닌 경우 로그인 페이지 표시 if (RequestContextHolder.getRequestAttributes().getAttribute("sessionVO", RequestAttributes.SCOPE_SESSION) == null) { response.sendRedirect("/login/login.do"); diff --git a/src/main/java/kr/co/hconnect/controller/SampleController.java b/src/main/java/kr/co/hconnect/controller/SampleController.java deleted file mode 100644 index 5630b44..0000000 --- a/src/main/java/kr/co/hconnect/controller/SampleController.java +++ /dev/null @@ -1,20 +0,0 @@ -package kr.co.hconnect.controller; - -import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.RequestMapping; - -/** - * 샘플 대쉬보드 컨트롤러 - */ -@Controller -@RequestMapping("/sample") -public class SampleController { - /** - * 샘플 대쉬보드 페이지 호출 - * @return 측정항목 페이지 - */ - @RequestMapping("/home.do") - public String itemHome(){ - return "sample/sample"; - } -} diff --git a/src/main/java/kr/co/hconnect/rest/SampleController.java b/src/main/java/kr/co/hconnect/rest/SampleController.java new file mode 100644 index 0000000..5b233f7 --- /dev/null +++ b/src/main/java/kr/co/hconnect/rest/SampleController.java @@ -0,0 +1,18 @@ +package kr.co.hconnect.rest; + +import kr.co.hconnect.vo.SampleVO; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("/api") +public class SampleController { + + @GetMapping("/sample") + public SampleVO doSample(@RequestBody SampleVO sampleVO) { + return sampleVO; + } + +} diff --git a/src/main/java/kr/co/hconnect/vo/SampleVO.java b/src/main/java/kr/co/hconnect/vo/SampleVO.java new file mode 100644 index 0000000..83cc186 --- /dev/null +++ b/src/main/java/kr/co/hconnect/vo/SampleVO.java @@ -0,0 +1,25 @@ +package kr.co.hconnect.vo; + +import com.fasterxml.jackson.annotation.JsonFormat; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import lombok.ToString; +import org.springframework.format.annotation.DateTimeFormat; + +import java.time.LocalDate; +import java.time.LocalTime; + +@Getter +@Setter +@NoArgsConstructor +@ToString +public class SampleVO { + + private String field1; + @JsonFormat(pattern = "yyyyMMdd") + private LocalDate field2; + @JsonFormat(pattern = "HHmmss") + private LocalTime field3; + +} diff --git a/src/main/resources/config/dispatcher-servlet.xml b/src/main/resources/config/dispatcher-servlet.xml index 1d433e4..740f78a 100644 --- a/src/main/resources/config/dispatcher-servlet.xml +++ b/src/main/resources/config/dispatcher-servlet.xml @@ -21,6 +21,7 @@ + diff --git a/src/main/webapp/WEB-INF/web.xml b/src/main/webapp/WEB-INF/web.xml index 4ff1089..61963c5 100644 --- a/src/main/webapp/WEB-INF/web.xml +++ b/src/main/webapp/WEB-INF/web.xml @@ -22,15 +22,20 @@ 1 + + + dispatcherServlet + /* + encodingFilter @@ -49,6 +54,7 @@ HTMLTagFilter egovframework.rte.ptl.mvc.filter.HTMLTagFilter + + + HTMLTagFilter + * + \ No newline at end of file