Complete the code to define a Spring Boot controller method that handles GET requests.
@RestController public class HelloController { @GetMapping("/hello") public String sayHello() { return [1]; } }
The method must return a string literal wrapped in quotes to send as the response body.
Complete the code to extract a path variable named 'id' in a Spring Boot controller method.
@GetMapping("/item/[1]") public String getItem(@PathVariable String id) { return "Item: " + id; }
Path variables in Spring Boot are defined with curly braces in the URL pattern.
Fix the error in the code to correctly map a POST request with a JSON body to a Java object.
@PostMapping("/add") public ResponseEntity<String> addItem([1] Item item) { // process item return ResponseEntity.ok("Added"); }
The @RequestBody annotation tells Spring Boot to convert the JSON request body into a Java object.
Fill both blanks to create a Spring Boot controller method that handles PUT requests and returns a ResponseEntity with status 204.
@PutMapping("/update/[1]") public ResponseEntity<Void> updateItem(@PathVariable String id, @RequestBody Item item) { // update logic return ResponseEntity.[2](); }
The path variable is marked with curly braces. Returning ResponseEntity.noContent() sends HTTP 204 status.
Fill all three blanks to create a Spring Boot controller method that handles DELETE requests, extracts an 'id' path variable, and returns a ResponseEntity with status 200 and a message.
@DeleteMapping("/delete/[1]") public ResponseEntity<String> deleteItem(@PathVariable String [2]) { // delete logic return ResponseEntity.[3]("Deleted item " + [2]); }
The path variable and method parameter must have the same name 'id'. ResponseEntity.ok() returns HTTP 200 with a message.