-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
React 활용 - 4 : axios 사용하여 Spring에 데이터 전송하기
- Loading branch information
Showing
4 changed files
with
68 additions
and
19 deletions.
There are no files selected for viewing
20 changes: 20 additions & 0 deletions
20
reactBootTemplate/src/main/java/com/reactboot/template/WebConfig.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.reactboot.template; | ||
|
||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.web.servlet.config.annotation.CorsRegistry; | ||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; | ||
|
||
@Configuration | ||
public class WebConfig implements WebMvcConfigurer { | ||
/** | ||
* 개발 환경에서의 크로스 도메인 이슈를 해결하기 위한 코드로 | ||
* 운영 환경에 배포할 경우에는 15~18행을 주석 처리합니다. | ||
* | ||
* ※크로스 도메인 이슈: 브라우저에서 다른 도메인으로 URL 요청을 하는 경우 나타나는 보안문제 | ||
*/ | ||
@Override | ||
public void addCorsMappings(CorsRegistry registry) { | ||
registry.addMapping("/**").allowedOrigins("*") | ||
.allowedMethods("GET", "POST"); | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
reactBootTemplate/src/main/java/com/reactboot/template/controller/TestController.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,34 @@ | ||
package com.reactboot.template.controller; | ||
|
||
import java.sql.SQLException; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import javax.servlet.http.HttpServletRequest; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestMethod; | ||
import org.springframework.web.bind.annotation.ResponseBody; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
|
||
@RestController | ||
@RequestMapping("/test") | ||
public class TestController { | ||
|
||
/** | ||
* @param requestMap | ||
* @return Map<String, Object> | ||
* @throws SQLException | ||
* @description Axios test | ||
*/ | ||
@ResponseBody | ||
@RequestMapping(value="AxiosTest.do", method=RequestMethod.POST) | ||
public Map<String,Object> AxiosTest (HttpServletRequest request,@RequestBody Map<String, Object> paramMap) throws SQLException { | ||
System.out.println("paramMap ==>"+ paramMap); | ||
Map<String,Object> resultMap = new HashMap<String,Object>(); | ||
resultMap.put("java return", "im java"); | ||
return resultMap; | ||
} | ||
|
||
} |
19 changes: 0 additions & 19 deletions
19
reactBootTemplate/src/webapp/reactspringfront/package-lock.json
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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