Skip to content

Commit

Permalink
#4 REST API 개발환경 설정 #4
Browse files Browse the repository at this point in the history
  • Loading branch information
cloudwisx committed Nov 25, 2021
1 parent 4843d46 commit aadb056
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 22 deletions.
5 changes: 5 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,11 @@
<artifactId>jackson-annotations</artifactId>
<version>2.9.9</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jsr310</artifactId>
<version>2.9.9</version>
</dependency>

<!-- Lombok -->
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
20 changes: 0 additions & 20 deletions src/main/java/kr/co/hconnect/controller/SampleController.java

This file was deleted.

18 changes: 18 additions & 0 deletions src/main/java/kr/co/hconnect/rest/SampleController.java
Original file line number Diff line number Diff line change
@@ -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;
}

}
25 changes: 25 additions & 0 deletions src/main/java/kr/co/hconnect/vo/SampleVO.java
Original file line number Diff line number Diff line change
@@ -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;

}
2 changes: 2 additions & 0 deletions src/main/resources/config/dispatcher-servlet.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
</property>
<property name="messageConverters">
<list>
<!-- 왜 필요한지 이유를 모르겠음
<bean class="org.springframework.http.converter.StringHttpMessageConverter">
<property name="supportedMediaTypes">
<list>
Expand All @@ -29,6 +30,7 @@
</list>
</property>
</bean>
-->
<bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">
<property name="objectMapper">
<bean class="org.springframework.http.converter.json.Jackson2ObjectMapperFactoryBean">
Expand Down
13 changes: 12 additions & 1 deletion src/main/webapp/WEB-INF/web.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,20 @@
<load-on-startup>1</load-on-startup>
</servlet>

<!--
<servlet-mapping>
<servlet-name>dispatcherServlet</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>

<servlet-mapping>
<servlet-name>dispatcherServlet</servlet-name>
<url-pattern>*.ajax</url-pattern>
</servlet-mapping>
-->
<servlet-mapping>
<servlet-name>dispatcherServlet</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>

<filter>
<filter-name>encodingFilter</filter-name>
Expand All @@ -49,11 +54,17 @@
<filter-name>HTMLTagFilter</filter-name>
<filter-class>egovframework.rte.ptl.mvc.filter.HTMLTagFilter</filter-class>
</filter>
<!--
<filter-mapping>
<filter-name>HTMLTagFilter</filter-name>
<url-pattern>*.do</url-pattern>
</filter-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
-->
<filter-mapping>
<filter-name>HTMLTagFilter</filter-name>
<url-pattern>*</url-pattern>
</filter-mapping>
</web-app>

0 comments on commit aadb056

Please sign in to comment.