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.Inherited;
022import java.lang.annotation.Retention;
023import java.lang.annotation.RetentionPolicy;
024import java.lang.annotation.Target;
025
026import org.springframework.core.annotation.AliasFor;
027
028/**
029 * Annotation that indicates the session attributes that a specific handler uses.
030 *
031 * <p>This will typically list the names of model attributes which should be
032 * transparently stored in the session or some conversational storage,
033 * serving as form-backing beans. <b>Declared at the type level</b>, applying
034 * to the model attributes that the annotated handler class operates on.
035 *
036 * <p><b>NOTE:</b> Session attributes as indicated using this annotation
037 * correspond to a specific handler's model attributes, getting transparently
038 * stored in a conversational session. Those attributes will be removed once
039 * the handler indicates completion of its conversational session. Therefore,
040 * use this facility for such conversational attributes which are supposed
041 * to be stored in the session <i>temporarily</i> during the course of a
042 * specific handler's conversation.
043 *
044 * <p>For permanent session attributes, e.g. a user authentication object,
045 * use the traditional {@code session.setAttribute} method instead.
046 * Alternatively, consider using the attribute management capabilities of the
047 * generic {@link org.springframework.web.context.request.WebRequest} interface.
048 *
049 * <p><b>NOTE:</b> When using controller interfaces (e.g. for AOP proxying),
050 * make sure to consistently put <i>all</i> your mapping annotations &mdash;
051 * such as {@code @RequestMapping} and {@code @SessionAttributes} &mdash; on
052 * the controller <i>interface</i> rather than on the implementation class.
053 *
054 * @author Juergen Hoeller
055 * @author Sam Brannen
056 * @since 2.5
057 */
058@Target({ElementType.TYPE})
059@Retention(RetentionPolicy.RUNTIME)
060@Inherited
061@Documented
062public @interface SessionAttributes {
063
064        /**
065         * Alias for {@link #names}.
066         */
067        @AliasFor("names")
068        String[] value() default {};
069
070        /**
071         * The names of session attributes in the model that should be stored in the
072         * session or some conversational storage.
073         * <p><strong>Note</strong>: This indicates the <em>model attribute names</em>.
074         * The <em>session attribute names</em> may or may not match the model attribute
075         * names. Applications should therefore not rely on the session attribute
076         * names but rather operate on the model only.
077         * @since 4.2
078         */
079        @AliasFor("value")
080        String[] names() default {};
081
082        /**
083         * The types of session attributes in the model that should be stored in the
084         * session or some conversational storage.
085         * <p>All model attributes of these types will be stored in the session,
086         * regardless of attribute name.
087         */
088        Class<?>[] types() default {};
089
090}