08-02-2023, 09:11 AM
I have gone through the Spring documentation to know about `@RequestBody`, and they have given the following explanation:
> The `@RequestBody` method parameter annotation indicates that a method parameter should be bound to the value of the HTTP request body. For example:
@RequestMapping(value = "/something", method = RequestMethod.PUT)
public void handle(@RequestBody String body, Writer writer) throws IOException {
writer.write(body);
}
> You convert the request body to the method argument by using an `HttpMessageConverter`. `HttpMessageConverter` is responsible for converting from the HTTP request message to an object and converting from an object to the HTTP response body.
>`DispatcherServlet` supports annotation based processing using the `DefaultAnnotationHandlerMapping` and `AnnotationMethodHandlerAdapter`. In Spring 3.0 the `AnnotationMethodHandlerAdapter` is extended to support the `@RequestBody` and has the following `HttpMessageConverter`s registered by default:
> ...
but my confusion is the sentence they have written in the doc that is
> The @RequestBody method parameter annotation indicates that a method parameter should be bound to the value of the HTTP request body.
What do they mean by that? Can anyone provide me an example?
The `@RequestParam` definition in spring doc is
> Annotation which indicates that a method parameter should be bound to a web request parameter. Supported for annotated handler methods in `Servlet` and `Portlet` environments.
I have become confused between them. Please, help me with an example on how they are different from each other.
> The `@RequestBody` method parameter annotation indicates that a method parameter should be bound to the value of the HTTP request body. For example:
@RequestMapping(value = "/something", method = RequestMethod.PUT)
public void handle(@RequestBody String body, Writer writer) throws IOException {
writer.write(body);
}
> You convert the request body to the method argument by using an `HttpMessageConverter`. `HttpMessageConverter` is responsible for converting from the HTTP request message to an object and converting from an object to the HTTP response body.
>`DispatcherServlet` supports annotation based processing using the `DefaultAnnotationHandlerMapping` and `AnnotationMethodHandlerAdapter`. In Spring 3.0 the `AnnotationMethodHandlerAdapter` is extended to support the `@RequestBody` and has the following `HttpMessageConverter`s registered by default:
> ...
but my confusion is the sentence they have written in the doc that is
> The @RequestBody method parameter annotation indicates that a method parameter should be bound to the value of the HTTP request body.
What do they mean by that? Can anyone provide me an example?
The `@RequestParam` definition in spring doc is
> Annotation which indicates that a method parameter should be bound to a web request parameter. Supported for annotated handler methods in `Servlet` and `Portlet` environments.
I have become confused between them. Please, help me with an example on how they are different from each other.