Bird
0
0

Which annotation is used to trigger validation on a request body object in a Spring Boot controller method?

easy📝 Conceptual Q2 of 15
Spring Boot - Request and Response Handling
Which annotation is used to trigger validation on a request body object in a Spring Boot controller method?
A@RequestBody
B@Autowired
C@ResponseBody
D@Valid
Step-by-Step Solution
Solution:
  1. Step 1: Identify annotation for validation trigger

    The @Valid annotation triggers validation on the annotated object, such as a request body DTO.
  2. Step 2: Differentiate from other annotations

    @RequestBody binds the HTTP body to the object but does not trigger validation itself.
  3. Final Answer:

    @Valid triggers validation on request body objects. -> Option D
  4. Quick Check:

    @Valid triggers validation = C [OK]
Quick Trick: Use @Valid on request body to enable validation [OK]
Common Mistakes:
  • Confusing @RequestBody with validation trigger
  • Using @Autowired instead of validation annotations
  • Thinking @ResponseBody triggers validation

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Spring Boot Quizzes