001/* 002 * Copyright 2002-2016 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; 024 025import org.springframework.core.annotation.AliasFor; 026 027/** 028 * Annotation which indicates that a method parameter should be bound to an HTTP cookie. 029 * 030 * <p>The method parameter may be declared as type {@link javax.servlet.http.Cookie} 031 * or as cookie value type (String, int, etc.). 032 * 033 * @author Juergen Hoeller 034 * @author Sam Brannen 035 * @since 3.0 036 * @see RequestMapping 037 * @see RequestParam 038 * @see RequestHeader 039 * @see org.springframework.web.bind.annotation.RequestMapping 040 */ 041@Target(ElementType.PARAMETER) 042@Retention(RetentionPolicy.RUNTIME) 043@Documented 044public @interface CookieValue { 045 046 /** 047 * Alias for {@link #name}. 048 */ 049 @AliasFor("name") 050 String value() default ""; 051 052 /** 053 * The name of the cookie to bind to. 054 * @since 4.2 055 */ 056 @AliasFor("value") 057 String name() default ""; 058 059 /** 060 * Whether the cookie is required. 061 * <p>Defaults to {@code true}, leading to an exception being thrown 062 * if the cookie is missing in the request. Switch this to 063 * {@code false} if you prefer a {@code null} value if the cookie is 064 * not present in the request. 065 * <p>Alternatively, provide a {@link #defaultValue}, which implicitly 066 * sets this flag to {@code false}. 067 */ 068 boolean required() default true; 069 070 /** 071 * The default value to use as a fallback. 072 * <p>Supplying a default value implicitly sets {@link #required} to 073 * {@code false}. 074 */ 075 String defaultValue() default ValueConstants.DEFAULT_NONE; 076 077}