MVC4 [Java] 스프링 MVC RequestBody Http message body에 데이터를 직접 담아서 요청하는 방법에 대해 알아보자 HTTP 메시지 바디의 데이터를 InputStream을 사용해서 직접 읽을 수 있다 @Slf4j @Controller public class RequestBodyStringController { @PostMapping("/request-body-string-v1") public void requestBodyString(HttpServletRequest request, HttpServletResponse response) throws IOException { ServletInputStream inputStream = request.getInputStream(); String messageBody = StreamUtils... 2022. 2. 1. [Java] MVC 스프링 RequestParam 예시 HTTP 웹 사이트에서 파라미터 값을 사용할 때에 여러 가지 방법이 있다 그중에 첫 번째 방법은 request.getParameter를 사용해서 넘기는 방법이다 @Slf4j @Controller public class RequestParamController { @RequestMapping("/request-param-v1") public void requestParamV1(HttpServletRequest request, HttpServletResponse response) throws IOException { String username = request.getParameter("username"); int age = Integer.parseInt(request.getParameter("age"));.. 2022. 1. 31. [Java] API형식으로 요청 매핑 받기 스프링에서 지원하는 API를 사용하여 요청 매핑을 받을 수 있다 RequestMapping을 Class에 어노테이션 해서 디폴트 URL값을 인식해준다 GET방식 @GetMapping public String user() { return "get users"; } POST방식 @PostMapping public String addUser() { return "post user"; } GET방식 매개변수 포함하여 받기 @GetMapping("/{userId}") public String findUser(@PathVariable String userId) { return "get userId" + userId; } UPDATE @PatchMapping("/{userId}") public String updat.. 2022. 1. 30. [Java] Mapping 요청 예시 Spring Mapping 요청을 받는 예시를 알아보자 기본 파라미터 1개 파라미터 여러 개 기본 @RestController @RequestMapping(value = "/hello-basic", method = RequestMethod.GET) public String helloBasic() { log.info("helloBasic"); return "ok"; } @RestController @GetMapping(value = "/hello.basic") public String helloBasic() { log.info("helloBasic"); return "ok"; } requestMapping으로 주소를 매핑받고 방식은 Get방식으로 설정해준다 리턴 값을 “ok”로 받기 위해서 RestCont.. 2022. 1. 30. 이전 1 다음