How can you handle scenarios where both @RequestBody and @ResponseBody are required in a controller method in Spring Boot?

  • Use only @RequestParam to pass data between the client and server.
  • Combine @RequestParam and @ResponseBody in the method signature.
  • Utilize @ModelAttribute to encapsulate both input and output data.
  • Annotate the method with @RestController and @ResponseBody.
When both @RequestBody and @ResponseBody are required in a Spring Boot controller method, you can use @ModelAttribute (Option 3) to encapsulate both input and output data. This allows you to handle both incoming data and outgoing responses in a single object. The other options don't effectively handle both input and output scenarios or may not follow best practices for handling requests and responses in a Spring Boot controller.
Add your answer
Loading...

Leave a comment

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