Bird
0
0

Given the controller method:

medium📝 component behavior Q13 of 15
Spring Boot - REST Controllers
Given the controller method:
@GetMapping("/greet")
public String greet(@RequestParam String name) {
    return "Hello, " + name + "!";
}

What will be the output when accessing /greet?name=Anna?
AHello, Anna!
BHello, null!
CHello, !
DError: Missing required parameter
Step-by-Step Solution
Solution:
  1. Step 1: Understand @RequestParam behavior

    The method expects a query parameter 'name' which is required by default.
  2. Step 2: Check the URL query string

    The URL provides ?name=Anna, so the method receives "Anna" as the parameter.
  3. Final Answer:

    Hello, Anna! -> Option A
  4. Quick Check:

    Query param 'name' = Anna, output greeting = D [OK]
Quick Trick: If param is required and given, output uses it directly [OK]
Common Mistakes:
  • Assuming missing param causes null instead of error
  • Confusing query string with path variable
  • Expecting default value without setting one

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Spring Boot Quizzes