Bird
0
0

Which of the following is the correct way to use @RequestBody in a Spring Boot controller method parameter?

easy📝 Syntax Q3 of 15
Spring Boot - REST Controllers
Which of the following is the correct way to use @RequestBody in a Spring Boot controller method parameter?
Apublic void saveUser(@PathVariable User user)
Bpublic void saveUser(@RequestParam User user)
Cpublic void saveUser(User user)
Dpublic void saveUser(@RequestBody User user)
Step-by-Step Solution
Solution:
  1. Step 1: Recognize correct annotation for JSON body

    @RequestBody is used to bind JSON from the request body to the User object.
  2. Step 2: Differentiate from other annotations

    @RequestParam binds query parameters, @PathVariable binds URL path segments, and no annotation means no binding from body.
  3. Final Answer:

    public void saveUser(@RequestBody User user) -> Option D
  4. Quick Check:

    @RequestBody on method parameter = correct usage [OK]
Quick Trick: Use @RequestBody on method parameter to get JSON object [OK]
Common Mistakes:
  • Using @RequestParam instead of @RequestBody
  • Forgetting @RequestBody annotation
  • Using @PathVariable for JSON body

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Spring Boot Quizzes