spring-framework / org.springframework.web.bind.annotation / SessionAttributes

SessionAttributes

@Target([AnnotationTarget.CLASS, AnnotationTarget.FILE]) @Inherited class SessionAttributes

Annotation that indicates the session attributes that a specific handler uses.

This will typically list the names of model attributes which should be transparently stored in the session or some conversational storage, serving as form-backing beans. Declared at the type level, applying to the model attributes that the annotated handler class operates on.

NOTE: Session attributes as indicated using this annotation correspond to a specific handler's model attributes, getting transparently stored in a conversational session. Those attributes will be removed once the handler indicates completion of its conversational session. Therefore, use this facility for such conversational attributes which are supposed to be stored in the session temporarily during the course of a specific handler's conversation.

For permanent session attributes, e.g. a user authentication object, use the traditional session.setAttribute method instead. Alternatively, consider using the attribute management capabilities of the generic org.springframework.web.context.request.WebRequest interface.

NOTE: When using controller interfaces (e.g. for AOP proxying), make sure to consistently put all your mapping annotations — such as @RequestMapping and @SessionAttributes — on the controller interface rather than on the implementation class.

Author
Juergen Hoeller

Author
Sam Brannen

Since
2.5

Constructors

<init>

SessionAttributes(vararg value: String, names: Array<String>, types: Array<KClass<*>>)

Annotation that indicates the session attributes that a specific handler uses.

This will typically list the names of model attributes which should be transparently stored in the session or some conversational storage, serving as form-backing beans. Declared at the type level, applying to the model attributes that the annotated handler class operates on.

NOTE: Session attributes as indicated using this annotation correspond to a specific handler's model attributes, getting transparently stored in a conversational session. Those attributes will be removed once the handler indicates completion of its conversational session. Therefore, use this facility for such conversational attributes which are supposed to be stored in the session temporarily during the course of a specific handler's conversation.

For permanent session attributes, e.g. a user authentication object, use the traditional session.setAttribute method instead. Alternatively, consider using the attribute management capabilities of the generic org.springframework.web.context.request.WebRequest interface.

NOTE: When using controller interfaces (e.g. for AOP proxying), make sure to consistently put all your mapping annotations — such as @RequestMapping and @SessionAttributes — on the controller interface rather than on the implementation class.

Properties

names

val names: Array<String>

The names of session attributes in the model that should be stored in the session or some conversational storage.

Note: This indicates the model attribute names. The session attribute names may or may not match the model attribute names. Applications should therefore not rely on the session attribute names but rather operate on the model only.

types

val types: Array<KClass<*>>

The types of session attributes in the model that should be stored in the session or some conversational storage.

All model attributes of these types will be stored in the session, regardless of attribute name.

value

val value: Array<String>

Alias for #names.