Recall & Review
beginner
What is the purpose of the @RequestParam annotation in Spring Boot?
It is used to extract query string parameters from the URL in HTTP requests and bind them to method parameters in controller methods.
Click to reveal answer
beginner
How do you make a @RequestParam optional in a Spring Boot controller method?
Set the attribute 'required = false' in the @RequestParam annotation. For example: @RequestParam(required = false) String name.
Click to reveal answer
intermediate
What happens if a required @RequestParam is missing in the HTTP request?
Spring Boot throws a MissingServletRequestParameterException, resulting in a 400 Bad Request response by default.
Click to reveal answer
beginner
How can you provide a default value for a @RequestParam in Spring Boot?
Use the 'defaultValue' attribute in the annotation. For example: @RequestParam(defaultValue = "guest") String user.
Click to reveal answer
beginner
Show a simple example of a Spring Boot controller method using @RequestParam to get a 'page' query parameter.
@GetMapping("/items")
public String getItems(@RequestParam int page) {
return "Page number: " + page;
}
Click to reveal answer
What does @RequestParam do in a Spring Boot controller?
✗ Incorrect
The @RequestParam annotation binds query string parameters from the URL to method parameters.
How do you make a @RequestParam optional?
✗ Incorrect
Setting required = false makes the @RequestParam optional.
What is the default behavior if a required @RequestParam is missing?
✗ Incorrect
If a required @RequestParam is missing, Spring Boot throws an exception and returns 400 Bad Request.
How to provide a default value for a @RequestParam?
✗ Incorrect
The defaultValue attribute sets a default value if the parameter is missing.
Which HTTP method is commonly used with @RequestParam?
✗ Incorrect
@RequestParam is often used with GET requests to read query parameters.
Explain how @RequestParam works in Spring Boot and how to handle optional query parameters.
Think about how URLs pass data and how controller methods receive it.
You got /3 concepts.
Describe what happens when a required @RequestParam is missing in a request and how to avoid errors.
Consider error handling and parameter defaults.
You got /3 concepts.