Complete the code to extract a path variable named 'id' in a Spring Boot controller method.
@GetMapping("/items/[1]") public String getItem(@PathVariable String id) { return "Item ID: " + id; }
The path variable must be enclosed in curly braces inside the URL pattern, like /{id}.
Complete the method parameter to extract a query parameter named 'filter' in a Spring Boot controller.
public String getItems(@RequestParam(required = false) String [1]) { return "Filter: " + filter; }
The parameter name in the method must match the query parameter name, here 'filter'.
Fix the error in the annotation to correctly bind both path variable 'userId' and query parameter 'sort'.
@GetMapping("/users/[1]") public String getUser(@PathVariable String userId, @RequestParam String sort) { return userId + ": " + sort; }
Path variables must be enclosed in curly braces in the URL pattern.
Fill both blanks to define a method that handles path variable 'category' and optional query parameter 'page'.
@GetMapping("/products/[1]") public String listProducts(@PathVariable String [2], @RequestParam(required = false) Integer page) { return "Category: " + category + ", Page: " + page; }
The path variable in the URL must be {category} and the method parameter name must match category.
Fill all three blanks to create a method that handles path variables 'orderId' and 'itemId' and a query parameter 'status'.
@GetMapping("/orders/[1]/items/[2]") public String getOrderItem(@PathVariable String [3], @PathVariable String itemId, @RequestParam String status) { return "Order: " + orderId + ", Item: " + itemId + ", Status: " + status; }
The URL must have {orderId} and {itemId} as path variables. The method parameter for orderId must be named orderId.