Bird
0
0

Which of the following method signatures correctly handles a path variable id and a query parameter sort in Spring Boot?

easy📝 Syntax Q12 of 15
Spring Boot - Request and Response Handling
Which of the following method signatures correctly handles a path variable id and a query parameter sort in Spring Boot?
Apublic String getUser(@PathVariable String id, @RequestParam String sort)
Bpublic String getUser(@RequestParam String id, @PathVariable String sort)
Cpublic String getUser(@RequestParam String id, @RequestParam String sort)
Dpublic String getUser(@PathVariable String id, @PathVariable String sort)
Step-by-Step Solution
Solution:
  1. Step 1: Match annotations to parameter types

    Path variables come from the URL path, so use @PathVariable for id. Query parameters come after ?, so use @RequestParam for sort.
  2. Step 2: Check method signature correctness

    public String getUser(@PathVariable String id, @RequestParam String sort) correctly uses @PathVariable for id and @RequestParam for sort.
  3. Final Answer:

    public String getUser(@PathVariable String id, @RequestParam String sort) -> Option A
  4. Quick Check:

    Path variable = @PathVariable, Query param = @RequestParam [OK]
Quick Trick: Path variables use @PathVariable, query params use @RequestParam [OK]
Common Mistakes:
  • Swapping @PathVariable and @RequestParam
  • Using @PathVariable for query parameters
  • Missing one of the annotations

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Spring Boot Quizzes