0
0
Spring Bootframework~5 mins

@RequestParam for query strings in Spring Boot - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
ABinds query string parameters to method arguments
BMaps HTTP POST body to an object
CDefines a REST endpoint URL
DHandles exceptions globally
How do you make a @RequestParam optional?
ASet required = true
BUse @OptionalParam annotation
CUse @Nullable annotation
DSet required = false
What is the default behavior if a required @RequestParam is missing?
ASpring Boot uses null value
BSpring Boot uses defaultValue automatically
CSpring Boot throws an error and returns 400 Bad Request
DSpring Boot ignores the parameter
How to provide a default value for a @RequestParam?
AUse defaultValue attribute
BUse @Default annotation
CSet required = false only
DUse @Value annotation
Which HTTP method is commonly used with @RequestParam?
APOST
BGET
CPUT
DDELETE
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.