Bird
0
0

Given this Spring Boot controller method, what will be the response to a POST request to "/hello"?

medium📝 component behavior Q4 of 15
Spring Boot - REST Controllers
Given this Spring Boot controller method, what will be the response to a POST request to "/hello"?
@PostMapping("/hello")
public String greet() {
    return "Hello World!";
}
A404 Not Found
BHello World!
CMethod Not Allowed
DInternal Server Error
Step-by-Step Solution
Solution:
  1. Step 1: Analyze the method mapping and return value

    The method is mapped to POST requests at "/hello" and returns "Hello World!".
  2. Step 2: Determine the response for a POST request to "/hello"

    A POST request to "/hello" will invoke this method and return the string "Hello World!" as the response body.
  3. Final Answer:

    Hello World! -> Option B
  4. Quick Check:

    POST to /hello returns method string [OK]
Quick Trick: POST request triggers @PostMapping method response [OK]
Common Mistakes:
  • Expecting 404 if method exists
  • Confusing POST with GET request
  • Assuming error without exception

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Spring Boot Quizzes