backend만 구현함, 화면구현 x , vue, react와 연동
package com.example.restcontroller;
import java.util.HashMap;
import java.util.Map;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/rest_customer")
public class CustomerRestController {
// 127.0.0.1:9090/ROOT/api/rest_customer/join
@RequestMapping(value = "/join",
method = {RequestMethod.POST},
consumes = {MediaType.ALL_VALUE}, //이미지, json 등 모든 걸 다 받을 수 있음
produces = {MediaType.APPLICATION_JSON_VALUE}) // 반환된느 타입은 항상 json
public Map<String, Object> customerJoinPost(){ // return타입을 map으로
Map<String, Object> map = new HashMap<>()
map.put("status", 200);
return map;
}
}
consumes => 받는 타입 ALL_VALUE는 모든 걸 다 받는다.
produces => 반환되는 타입 json으로 잡았음.
postman에 입력하면
405에러가 나오는데 그 이유는 security때문에.
SecurityConfig에서 다음과 같이 설정
http.csrf().ignoringAntMatchers("/api/**");