In a Spring Boot application, you are required to develop a feature where the response body should be customized based on the client's preference. How would you implement this feature using Spring Boot annotations?
- Use the @ResponseBody annotation on controller methods and generate custom responses based on client preference in each method.
- Implement content negotiation with @RequestMapping annotations to handle client preferences automatically.
- Use the @RequestParam annotation to pass the client's preference as a parameter to controller methods and customize the response accordingly.
- Define a custom response handler class and annotate it with @RestControllerAdvice to handle client preferences for all controllers.
To implement a feature in a Spring Boot application where the response body is customized based on client preference, you should use content negotiation with @RequestMapping annotations. This allows Spring Boot to handle client preferences automatically. Option 2 is the recommended approach as it promotes clean and efficient code. The other options may require more manual coding and could be less maintainable.
Loading...
Related Quiz
- In Spring Boot, the _____ annotation is used to denote a reactive programming model in a controller.
- For custom authentication logic in Spring Security, developers can create a bean of type _____.
- What is the significance of the @MockBean annotation in Spring Boot testing?
- The Spring Cloud component _____ provides a simple, scalable, and flexible way to route API requests to microservices.
- You need to develop a Spring Boot application where the requirement is to have different request mappings based on the user's role. How would you design the request mappings and controller methods to fulfill this requirement?