Bird
0
0

In Spring Boot, what is the role of the @PathVariable annotation in a REST controller method?

easy📝 Conceptual Q1 of 15
Spring Boot - REST Controllers
In Spring Boot, what is the role of the @PathVariable annotation in a REST controller method?
AIt binds a method parameter to a URI template variable.
BIt binds a method parameter to a query string parameter.
CIt binds a method parameter to a request header value.
DIt binds a method parameter to a form data parameter.
Step-by-Step Solution
Solution:
  1. Step 1: Understand URI Templates

    URI templates contain variables enclosed in braces, e.g., /user/{id}.
  2. Step 2: Role of @PathVariable

    @PathVariable binds the method parameter to the value of the URI template variable.
  3. Final Answer:

    It binds a method parameter to a URI template variable. -> Option A
  4. Quick Check:

    Check if the parameter matches the URI variable [OK]
Quick Trick: Binds method param to URI variable, not query or headers [OK]
Common Mistakes:
  • Confusing @PathVariable with @RequestParam
  • Assuming it binds to headers or form data

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Spring Boot Quizzes