How can you customize the response status code of a controller method in Spring Boot?

  • By returning an instance of ResponseEntity with a custom status code.
  • By using the @ResponseStatus annotation with the desired code.
  • Modifying the application.properties file with a custom code.
  • Configuring the status code in the @GetMapping annotation.
To customize the response status code of a controller method in Spring Boot, you can return an instance of ResponseEntity with a custom status code. This allows fine-grained control over the response, including status codes, headers, and response bodies. The @ResponseStatus annotation is used to declare the default status code for the entire controller class, not for individual methods. The other options are not standard ways to customize the status code.
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *