001/* 002 * Copyright 2002-2015 the original author or authors. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * https://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017package org.springframework.web.bind.annotation; 018 019import java.lang.annotation.Documented; 020import java.lang.annotation.ElementType; 021import java.lang.annotation.Retention; 022import java.lang.annotation.RetentionPolicy; 023import java.lang.annotation.Target; 024import java.util.Map; 025 026import org.springframework.core.annotation.AliasFor; 027 028/** 029 * Annotation which indicates that a method parameter should be bound to a web 030 * request parameter. 031 * 032 * <p>Supported for annotated handler methods in Servlet and Portlet environments. 033 * 034 * <p>If the method parameter type is {@link Map} and a request parameter name 035 * is specified, then the request parameter value is converted to a {@link Map} 036 * assuming an appropriate conversion strategy is available. 037 * 038 * <p>If the method parameter is {@link java.util.Map Map<String, String>} or 039 * {@link org.springframework.util.MultiValueMap MultiValueMap<String, String>} 040 * and a parameter name is not specified, then the map parameter is populated 041 * with all request parameter names and values. 042 * 043 * @author Arjen Poutsma 044 * @author Juergen Hoeller 045 * @author Sam Brannen 046 * @since 2.5 047 * @see RequestMapping 048 * @see RequestHeader 049 * @see CookieValue 050 * @see org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter 051 * @see org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter 052 * @see org.springframework.web.portlet.mvc.annotation.AnnotationMethodHandlerAdapter 053 */ 054@Target(ElementType.PARAMETER) 055@Retention(RetentionPolicy.RUNTIME) 056@Documented 057public @interface RequestParam { 058 059 /** 060 * Alias for {@link #name}. 061 */ 062 @AliasFor("name") 063 String value() default ""; 064 065 /** 066 * The name of the request parameter to bind to. 067 * @since 4.2 068 */ 069 @AliasFor("value") 070 String name() default ""; 071 072 /** 073 * Whether the parameter is required. 074 * <p>Defaults to {@code true}, leading to an exception being thrown 075 * if the parameter is missing in the request. Switch this to 076 * {@code false} if you prefer a {@code null} value if the parameter is 077 * not present in the request. 078 * <p>Alternatively, provide a {@link #defaultValue}, which implicitly 079 * sets this flag to {@code false}. 080 */ 081 boolean required() default true; 082 083 /** 084 * The default value to use as a fallback when the request parameter is 085 * not provided or has an empty value. 086 * <p>Supplying a default value implicitly sets {@link #required} to 087 * {@code false}. 088 */ 089 String defaultValue() default ValueConstants.DEFAULT_NONE; 090 091}