Bird
0
0

Consider this Spring Boot controller method:

medium📝 component behavior Q5 of 15
Spring Boot - REST Controllers
Consider this Spring Boot controller method:
@DeleteMapping("/products/{productId}")
public ResponseEntity removeProduct(@PathVariable String productId) {
    return ResponseEntity.ok("Deleted product " + productId);
}

What is the output when a DELETE request is sent to /products/abc123?
A"Deleted product null"
B"Deleted product abc123"
C"Deleted product productId"
D404 Not Found
Step-by-Step Solution
Solution:
  1. Step 1: Understand the method behavior

    The method returns a string concatenating "Deleted product " with the productId path variable.
  2. Step 2: Substitute the path variable value

    For DELETE /products/abc123, productId = "abc123", so the response is "Deleted product abc123".
  3. Final Answer:

    "Deleted product abc123" -> Option B
  4. Quick Check:

    PathVariable string used in response = "Deleted product abc123" [OK]
Quick Trick: PathVariable strings appear exactly as in URL [OK]
Common Mistakes:
  • Returning variable name instead of value
  • Assuming null value
  • Expecting 404 without reason

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Spring Boot Quizzes