controller에서 파라미터를 받는 방법, @PathVariable과 @RequestBody

공식문서 : https://docs.spring.io/spring-framework/reference/integration/rest-clients.html#rest-http-interface-method-parameters

 

HTTP exchange 메서드는 아래와 같은 method signature을 지원한다.

@PathVariable

Add a variable for expand a placeholder in the request URL. The argument may be a Map<String, ?> with multiple variables, or an individual value. Type conversion is supported for non-String values.

요청 URL에 변수를 추가합니다. 인수는 여러 변수가 있는 Map<String, ?> 또는 개별 값일 수 있습니다. 문자열이 아닌 값의 경우 유형 변환이 지원됩니다.

Annotation which indicates that a method parameter should be bound to a URI template variable.

method parameter가 URI 템플릿 변수에 바인딩되어야 함을 나타내는 어노테이션이다.

 

@RequestBody

Provide the body of the request either as an Object to be serialized, or a Reactive Streams Publisher such as Mono, Flux, or any other async type supported through the configured ReactiveAdapterRegistry.

Http request의 본문 body를 직렬화할 Object 또는 Reactive Streams Publisher, 예를 들어 Mono, Flux. 또는 기타 비동기 유형(ReactiveAdapterRegistry)을 제공하시오.

 

You can use the @RequestBody annotation to have the request body read and deserialized into an Object through an HttpMessageReader.

@RequestBody 주석을 사용하여 Request body를 읽고 HttpMessageReader를 통해 객체로 역직렬화할 수 있습니다.