@RequestParam 在Intellij Idea 上的打开方式和@RequestMapping是一样的。
一、注解:
@Target(ElementType.PARAMETER)
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface RequestParam {}
二、源码
①、value
value:参数名字,即入参的请求参数名字,如username表示请求的参数区中的名字为username的参数的值将传入;
/**
* Alias for {@link #name}.
*/
@AliasFor("name")
String value() default "";
②、required
required:是否必须,默认是true,表示请求中一定要有相应的参数,否则将报404错误码;
/**
* Whether the parameter is required.
* <p>Defaults to {@code true}, leading to an exception being thrown
* if the parameter is missing in the request. Switch this to
* {@code false} if you prefer a {@code null} value if the parameter is
* not present in the request.
* <p>Alternatively, provide a {@link #defaultValue}, which implicitly
* sets this flag to {@code false}.
*/
boolean required() default true;
③defaultValue
defaultValue:默认值,表示如果请求中没有同名参数时的默认值,默认值可以是SpEL表达式,如“#{systemProperties['java.vm.version']}”。
/**
* The default value to use as a fallback when the request parameter is
* not provided or has an empty value.
* <p>Supplying a default value implicitly sets {@link #required} to
* {@code false}.
*/
String defaultValue() default ValueConstants.DEFAULT_NONE;
总结:
public String xxxx(
@RequestParam(value="user", required=true, defaultValue="wang") String user)
参考:@RequestParam详解