Bird
0
0

Which method signature correctly handles a path variable named 'userId' and a query parameter named 'active' in Spring Boot?

easy📝 Conceptual Q2 of 15
Spring Boot - Request and Response Handling
Which method signature correctly handles a path variable named 'userId' and a query parameter named 'active' in Spring Boot?
Apublic String getUser(@RequestBody String userId, @RequestParam boolean active)
Bpublic String getUser(@RequestParam String userId, @PathVariable boolean active)
Cpublic String getUser(@PathVariable String userId, @RequestParam boolean active)
Dpublic String getUser(@PathVariable String userId, @RequestBody boolean active)
Step-by-Step Solution
Solution:
  1. Step 1: Identify correct annotations for path and query params

    Path variables use @PathVariable, query parameters use @RequestParam.
  2. Step 2: Match parameter types and annotations

    public String getUser(@PathVariable String userId, @RequestParam boolean active) correctly uses @PathVariable for 'userId' and @RequestParam for 'active'.
  3. Final Answer:

    public String getUser(@PathVariable String userId, @RequestParam boolean active) -> Option C
  4. Quick Check:

    Path variable + query param = @PathVariable + @RequestParam [OK]
Quick Trick: Path variables use @PathVariable, query params use @RequestParam [OK]
Common Mistakes:
  • Swapping @PathVariable and @RequestParam annotations
  • Using @RequestBody for simple parameters
  • Incorrect parameter types for annotations

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Spring Boot Quizzes