Complete the code to define a REST controller in Spring Boot.
@[1] public class MyController { }
The @RestController annotation marks the class as a REST controller, which handles HTTP requests and returns data as JSON or XML.
Complete the code to map a GET request to the method.
@GetMapping("/[1]") public String greet() { return "Hello"; }
The @GetMapping("/hello") annotation maps HTTP GET requests for the path '/hello' to this method.
Fix the error in the method signature to accept a path variable.
@GetMapping("/user/[1]") public String getUser(@PathVariable String id) { return "User " + id; }
Path variables in Spring Boot are enclosed in curly braces like {id} in the URL mapping.
Fill both blanks to create a POST endpoint that accepts JSON data.
@PostMapping("/[1]") public ResponseEntity<String> createItem(@[2] Item item) { return ResponseEntity.ok("Created"); }
The @PostMapping("/items") maps POST requests to '/items'. The @RequestBody annotation tells Spring to convert JSON from the request body into the Item object.
Fill all three blanks to return a JSON map with filtered data.
Map<String, Integer> result = items.stream()
.filter(item -> item.getQuantity() [1] 10)
.collect(Collectors.toMap(
item -> item.getName().[2](),
item -> item.getQuantity() [3] 1
));This code filters items with quantity greater than 10, converts their names to uppercase for keys, and adds 1 to their quantity for values in the resulting map.