ResponseEntity,@ResponseBody,@ResponseStatus in java web services

0 votes
32 views
asked May 15 in JAVA by anonymous
Hi

   Give simple explain about the below

  ResponseEntity,

 @ResponseBody,

@ResponseStatus in java web services

1 Answer

0 votes
answered May 15 by admin (8,115 points)

ResponseEntity is meant to represent the entire HTTP response. You can control anything that goes into it: status code, headers, and body.

@ResponseBody is a marker for the HTTP response body and @ResponseStatus declares the status code of the HTTP response.

@ResponseStatus isn't very flexible. It marks the entire method so you have to be sure that your handler method will always behave the same way. And you still can't set the headers. You'd need the HttpServletResponse or a HttpHeaders parameter.

Basically, ResponseEntity lets you do more.

...