How can you handle different HTTP methods in a single method in a Spring Boot controller?
- Create separate controller classes for each HTTP method.
- Use multiple methods with different names for each HTTP method.
- Use the @RequestMapping annotation with the method parameter.
- Use the @RequestMethod annotation with the method parameter.
To handle different HTTP methods in a single method of a Spring Boot controller, you can use the @RequestMapping annotation with the method parameter. This allows you to specify which HTTP methods (GET, POST, PUT, DELETE, etc.) should be mapped to that method. Inside the method, you can use conditional logic to perform different actions based on the incoming HTTP method.
Loading...
Related Quiz
- In Spring Boot, to map HTTP GET requests to a specific handler method, the _____ annotation is used.
- When creating a custom error response in Spring Boot, the _____ method of the ResponseEntity class can be used to set the HTTP status code of the response.
- In Spring Boot, _____ allows developing reactive applications by providing an alternative to the traditional, servlet-based, blocking architecture.
- What is the primary role of a Resource Server in OAuth2?
- The @DataJpaTest annotation in Spring Boot is typically used to test _____.