Recall & Review
beginner
What is a path variable in Spring Boot?
A path variable is a part of the URL path that is treated as a variable. It is used to capture dynamic values from the URL, like an ID or name, and pass it to the controller method.
Click to reveal answer
beginner
How do you define a query parameter in a Spring Boot controller?
You define a query parameter by adding a method parameter annotated with @RequestParam. It captures values from the URL after the '?' symbol, like ?page=2.
Click to reveal answer
beginner
Show the annotation to capture a path variable named 'userId' in a Spring Boot controller method.
Use @PathVariable("userId") in the method parameter to capture the value from the URL path.
Click to reveal answer
intermediate
Can you use both @PathVariable and @RequestParam in the same Spring Boot controller method?
Yes, you can use both together to capture parts of the URL path and query parameters in the same method.
Click to reveal answer
intermediate
What happens if a required @RequestParam is missing in the request?
Spring Boot will return a 400 Bad Request error unless you set required=false or provide a defaultValue in the @RequestParam annotation.
Click to reveal answer
Which annotation is used to capture a path variable in Spring Boot?
✗ Incorrect
The @PathVariable annotation captures dynamic parts of the URL path.
How do you capture a query parameter named 'sort' in a Spring Boot controller?
✗ Incorrect
Use @RequestParam("sort") to capture query parameters from the URL.
What is the correct way to define a method that handles URL /users/{id} and query param ?active=true?
✗ Incorrect
Path variables come from the URL path, query params come after '?'. Use @PathVariable and @RequestParam respectively.
If a query parameter is optional, how do you declare it in Spring Boot?
✗ Incorrect
Setting required=false makes the query parameter optional.
What HTTP status code does Spring Boot return if a required query parameter is missing?
✗ Incorrect
Missing required query parameters cause a 400 Bad Request error.
Explain how to handle both path variables and query parameters in a single Spring Boot controller method.
Think about how URLs are structured with paths and queries.
You got /4 concepts.
Describe what happens if a required query parameter is missing in a Spring Boot request and how to avoid errors.
Consider user mistakes and how your app should respond.
You got /4 concepts.