Bird
0
0

Given this controller method:

medium📝 component behavior Q5 of 15
Spring Boot - Request and Response Handling
Given this controller method:
@PostMapping("/create")
public ResponseEntity create() {
  return new ResponseEntity<>("Created", HttpStatus.CREATED);
}

What will be the HTTP status code and response body?
AStatus 200 OK, body "Created"
BStatus 201 Created, body "Created"
CStatus 404 Not Found, empty body
DStatus 500 Internal Server Error, body "Created"
Step-by-Step Solution
Solution:
  1. Step 1: Analyze ResponseEntity constructor parameters

    The constructor is called with body "Created" and status HttpStatus.CREATED (201).
  2. Step 2: Confirm returned HTTP status and body

    The response will have status 201 Created and body "Created" as specified.
  3. Final Answer:

    Status 201 Created, body "Created" -> Option B
  4. Quick Check:

    ResponseEntity(body, status) returns given status and body [OK]
Quick Trick: ResponseEntity constructor sets body and status directly [OK]
Common Mistakes:
  • Assuming default 200 OK status
  • Ignoring the status parameter in constructor
  • Confusing POST with GET default status

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Spring Boot Quizzes