注释类型 RequestParam
@Target(PARAMETER) @Retention(RUNTIME) @Documented public @interface RequestParam
Annotation which indicates that a method parameter should be bound to a web request parameter.Supported for annotated handler methods in Spring MVC and Spring WebFlux as follows:
- In Spring MVC, "request parameters" map to query parameters, form data, and parts in multipart requests. This is because the Servlet API combines query parameters and form data into a single map called "parameters", and that includes automatic parsing of the request body.
- In Spring WebFlux, "request parameters" map to query parameters only. To work with all 3, query, form data, and multipart data, you can use data binding to a command object annotated with
ModelAttribute
.
If the method parameter type is
Map
and a request parameter name is specified, then the request parameter value is converted to aMap
assuming an appropriate conversion strategy is available.If the method parameter is
Map<String, String>
orMultiValueMap<String, String>
and a parameter name is not specified, then the map parameter is populated with all request parameter names and values.- 从以下版本开始:
- 2.5
- 作者:
- Arjen Poutsma, Juergen Hoeller, Sam Brannen
- 另请参阅:
RequestMapping
,RequestHeader
,CookieValue
required
boolean required
Whether the parameter is required.Defaults to
true
, leading to an exception being thrown if the parameter is missing in the request. Switch this tofalse
if you prefer anull
value if the parameter is not present in the request.Alternatively, provide a
defaultValue()
, which implicitly sets this flag tofalse
.- 默认值:
- true
defaultValue
String defaultValue
The default value to use as a fallback when the request parameter is not provided or has an empty value.Supplying a default value implicitly sets
required()
tofalse
.- 默认值:
- "\n\t\t\n\t\t\n\ue000\ue001\ue002\n\t\t\t\t\n"