Posts

Showing posts with the label @ResponseBody

Spring @ResponseBody Annotation Example

Image
In this section we will learn about  @ ResponseBody  Annotation.   @ ResponseBody   is a Spring annotation which binds a method return value to the web response body. It is not interpreted as a view name. It uses HTTP Message converters to convert the return value to HTTP response body, based on the content-type in the request HTTP header. The @ResponseBody annotation is used at method level or method return type level.  The @ResponseBody constructs the response body as JSON or XML or other media type based on following points.  1. MessageConverter configured in the application.  2. Media-type configured by produces attribute in annotations @RequestMapping , @GetMapping etc.  3. Media-type configured by accept request header.  The @ResponseBody only configures body of response. To set response status code we use @ResponseStatus annotation at method level. If status code is not set explicitly, default status code is set to response. The @...