1. What is the main purpose of the @RequestParam annotation in Spring MVC?
Why:@RequestParam is used to bind parameter values of the query string to controller method parameters.
2. What is the default value of the required element in @RequestParam?
Why: The required element defaults to true, meaning the parameter must be present in the request.
3. What happens when a required @RequestParam is missing from the request?
Why: If a required parameter is missing, Spring returns status code 400.
4. How can you make a @RequestParam optional so that a missing parameter does not cause an error?
Why: Setting required = false allows the parameter to be null if it is not present in the request.
5. What is the purpose of the defaultValue element in @RequestParam?
Why:defaultValue is used as a fallback when the request parameter is not provided or has an empty value.
6. What effect does supplying a defaultValue have on the required setting of @RequestParam?
Why: Supplying a default value implicitly sets required to false, so you do not need to specify required = false separately.
7. How can a controller method bind multiple different query parameters using @RequestParam?
Why: A method can have any number of @RequestParam annotations, each binding a different query parameter.
8. What does a Map annotated with @RequestParam contain?
Why: When a method parameter is a Map annotated with @RequestParam, it contains all the request query parameters.
9. Does Spring MVC automatically convert a query parameter value to a non-String type (such as int) when using @RequestParam?
Why: Spring MVC performs automatic type conversion for simple types, including int, long, and Date.
10. Which annotation is used to customize the date format when binding a date query parameter with @RequestParam?
Why:@DateTimeFormat can be used alongside @RequestParam to specify the format of a date parameter.
11. Why does defining different @RequestParam names on methods with the same base URI cause an ambiguous mapping error?
Why: Different request parameters do not define different URI paths. If the URI is the same, Spring cannot resolve which method to call, causing an ambiguous mapping exception.
12. How can ambiguity be resolved when two handler methods have the same URI path but expect different query parameters?
Why: Using @RequestMapping(params = "...") allows Spring to distinguish the methods based on the presence of a specific request parameter.
13. In @RequestParam, what is the relationship between the name attribute and the value attribute?
Why:name is an alias for value. Both are used to specify the name of the request parameter to bind to.
14. What is required for @RequestParam to bind a query parameter when the value element is omitted?
Why: When value is omitted, Spring uses the method parameter name to match the query parameter. This requires the code to be compiled with debugging information.
15. What value does a @RequestParam method argument receive if the request parameter is missing and required is set to false?
Why: If required = false and the parameter is absent, the method argument is set to null.