SPRING 3

@RequestBody, @ResponseBody - HTTP Message Body 조회, 반환

요청 파라미터(HTML Form으로 전송 및 쿼리스트링) 은 @RequestParam, @ModelAttribute를 사용해서 데이터를 조회하지만 HTTP 메시지 바디에 있는 데이터는 해당 어노테이션들로는 조회가 불가능하다. HTTP 메시지 바디를 조회할 수 있는 가장 기본적인 방법은 InputStream과 OutputStream을 사용하는 것이다. @PostMapping("/request-body-string-stream") public void requestBodyStringStream(InputStream inputStream, Writer responseWriter) throws IOException { String messageBody = StreamUtils.copyToString(inputS..

SPRING 2023.05.21

@RequestParam @ModelAttribute - HTTP 요청 파라미터

@RequestParam : 파라미터 이름으로 바인딩 속성 : value, requried, defaultValue value : 요청된 데이터의 키를 명시 바인딩 대상이 되는 변수명과 키 이름이 같으면 value 속성은 생략 가능 // 요청 url localhost:8080/request-param?username=user&age=28 @RequestMapping("/request-param") public String requestParam( @RequestParam String username, @RequestParam int age) { log.info("username={}, age={}",username, age); return "ok"; } required : 요청 파라미터 필수 여부, 기본..

SPRING 2023.05.17

@RequestMapping - 요청 매핑

@RequsetMapping(value = "/hello-request") 은 value에 해당하는 값인 ex) /hello-request이라는 URL 요청이 오면 해당 어노테이션이 붙은 메서드를 실행하도록 매핑한다. @RequestMapping(value = "/hello-request") public String helloRequest() { return "ok"; } 즉, /hello-request로 URL 요청을 하면 helloRequest 메서드가 실행이 된다. method 속성 @RequestMapping(value = "/hello-request", method = RequestMethod.Get) URL 요청 방식이 method에 해당하는 요청 방식과 같아야 매핑을 해주는 역할을 한다. @..

SPRING 2023.05.14