I have gone through the Spring documentation to know about @RequestBody, and they have given the following explanation:
The
@RequestBodymethod 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.HttpMessageConverteris responsible for converting from the HTTP request message to an object and converting from an object to the HTTP response body.
DispatcherServletsupports annotation based processing using theDefaultAnnotationHandlerMappingandAnnotationMethodHandlerAdapter. In Spring 3.0 theAnnotationMethodHandlerAdapteris extended to support the@RequestBodyand has the followingHttpMessageConverters 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
ServletandPortletenvironments.
I have become confused between them. Please, help me with an example on how they are different from each other.