Bird
0
0

In Spring Boot, which annotation is used to specify the HTTP status code for a controller method's response?

easy📝 Conceptual Q1 of 15
Spring Boot - Request and Response Handling
In Spring Boot, which annotation is used to specify the HTTP status code for a controller method's response?
A@ResponseStatus
B@RequestMapping
C@GetMapping
D@Controller
Step-by-Step Solution
Solution:
  1. Step 1: Understand the purpose of @ResponseStatus

    The @ResponseStatus annotation allows you to define the HTTP status code that a controller method should return.
  2. Step 2: Differentiate from other annotations

    @RequestMapping and @GetMapping define the URL and HTTP method, while @Controller marks a class as a controller. Only @ResponseStatus sets the status code.
  3. Final Answer:

    @ResponseStatus -> Option A
  4. Quick Check:

    Annotation for HTTP status = @ResponseStatus [OK]
Quick Trick: Use @ResponseStatus to set HTTP status codes easily [OK]
Common Mistakes:
  • Confusing @RequestMapping with status code setting
  • Using @Controller to set status code
  • Assuming @GetMapping sets status code

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Spring Boot Quizzes