Bird
0
0

Given the controller method:

medium📝 component behavior Q4 of 15
Spring Boot - REST Controllers
Given the controller method:
@GetMapping("/search")
public String search(@RequestParam String query) {
    return "You searched for: " + query;
}

What will be the output if the URL is /search?query=books?
AYou searched for: books
BYou searched for: query
CYou searched for: null
DError: Missing required parameter
Step-by-Step Solution
Solution:
  1. Step 1: Understand parameter binding

    The query parameter 'query' is passed as 'books' in the URL, so it binds to the method parameter.
  2. Step 2: Check method return

    The method returns the string concatenated with the query value, so output is 'You searched for: books'.
  3. Final Answer:

    You searched for: books -> Option A
  4. Quick Check:

    Query param value = "books" output [OK]
Quick Trick: Query param value appears in method output [OK]
Common Mistakes:
  • Confusing parameter name with literal string
  • Expecting null if parameter is present
  • Assuming error when parameter is provided

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Spring Boot Quizzes