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 theDefaultAnnotationHandlerMapping
andAnnotationMethodHandlerAdapter
. In Spring 3.0 theAnnotationMethodHandlerAdapter
is extended to support the@RequestBody
and has the followingHttpMessageConverter
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
andPortlet
environments.
I have become confused between them. Please, help me with an example on how they are different from each other.