Complete the code to return HTTP status 200 OK from a controller method.
return new ResponseEntity<>("Success", [1]);
The HttpStatus.OK constant represents the 200 OK status code, which means the request was successful.
Complete the code to return HTTP status 404 Not Found when a resource is missing.
return new ResponseEntity<>("Resource not found", [1]);
The HttpStatus.NOT_FOUND constant represents the 404 status code, which means the requested resource was not found.
Fix the error in returning HTTP status 201 Created after creating a resource.
return new ResponseEntity<>(createdObject, [1]);
HTTP status 201 Created is represented by HttpStatus.CREATED and indicates a resource was successfully created.
Fill both blanks to return HTTP 400 Bad Request with a custom error message.
return new ResponseEntity<>("[1]", [2]);
The message "Invalid input data" explains the error, and HttpStatus.BAD_REQUEST returns the 400 status code indicating a client error.
Fill all three blanks to return HTTP 500 Internal Server Error with a detailed message and log the error.
logger.error("Error occurred: [1]"); return new ResponseEntity<>("[2]", [3]);
The logger records the exception message, the response message explains the error, and HttpStatus.INTERNAL_SERVER_ERROR returns the 500 status code.