Spring Boot - Request and Response HandlingWhich of the following is the correct syntax to return a 201 Created status with a ResponseEntity in Spring Boot?Areturn ResponseEntity.status(201, object);Breturn new ResponseEntity<>(object, HttpStatus.CREATED);Creturn ResponseEntity.created(object);Dreturn new ResponseEntity<>(HttpStatus.CREATED, object);Check Answer
Step-by-Step SolutionSolution:Step 1: Check ResponseEntity constructor usageThe constructor takes the body first, then the status code, so new ResponseEntity<>(object, HttpStatus.CREATED) is correct.Step 2: Analyze other optionsB is invalid syntax as status() takes only one argument; C is incorrect because created() expects a URI; D has parameters reversed.Final Answer:return new ResponseEntity<>(object, HttpStatus.CREATED); -> Option BQuick Check:Constructor order: body, status [OK]Quick Trick: ResponseEntity constructor: body first, then status [OK]Common Mistakes:Swapping parameters in ResponseEntity constructorUsing created() without URI argumentConfusing builder and constructor syntax
Master "Request and Response Handling" in Spring Boot9 interactive learning modes - each teaches the same concept differentlyLearnWhyDeepVisualTryChallengeProjectRecallPerf
More Spring Boot Quizzes Application Configuration - application.yml alternative - Quiz 7medium Exception Handling - @ControllerAdvice for global handling - Quiz 12easy Inversion of Control and Dependency Injection - @Autowired for dependency injection - Quiz 5medium REST Controllers - @RequestParam for query strings - Quiz 10hard Request and Response Handling - Custom response headers - Quiz 12easy Spring Annotations - Why annotations drive Spring Boot - Quiz 5medium Spring Annotations - @Value for property injection - Quiz 1easy Spring Annotations - @Configuration and @Bean - Quiz 9hard Spring Annotations - @Scope for bean scope - Quiz 6medium Spring Boot Fundamentals - Running a Spring Boot application - Quiz 6medium