If you need to create a Spring Boot component responsible for handling HTTP requests and responses, which annotation should you use, and how would you set up the methods within this component?

  • @Controller with methods annotated as @ResponseBody.
  • @Repository with methods annotated as @PostMapping.
  • @RestController with methods annotated as @RequestMapping.
  • @Service with methods annotated as @GetMapping.
In Spring Boot, you would use the @RestController annotation for creating components that handle HTTP requests and responses. Methods within this component should be annotated with @RequestMapping or its shortcut annotations like @GetMapping, @PostMapping, etc., to define the request mapping for each method. The @RestController annotation combines @Controller and @ResponseBody, making it suitable for RESTful web services.
Add your answer
Loading...

Leave a comment

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