spring-framework / org.springframework.web.method.annotation / SessionAttributesHandler

SessionAttributesHandler

open class SessionAttributesHandler

Manages controller-specific session attributes declared via SessionAttributes. Actual storage is delegated to a SessionAttributeStore instance.

When a controller annotated with @SessionAttributes adds attributes to its model, those attributes are checked against names and types specified via @SessionAttributes. Matching model attributes are saved in the HTTP session and remain there until the controller calls SessionStatus#setComplete().

Author
Rossen Stoyanchev

Author
Juergen Hoeller

Since
3.1

Constructors

<init>

SessionAttributesHandler(handlerType: Class<*>, sessionAttributeStore: SessionAttributeStore)

Create a new instance for a controller type. Session attribute names and types are extracted from the @SessionAttributes annotation, if present, on the given type.

Functions

cleanupAttributes

open fun cleanupAttributes(request: WebRequest): Unit

Remove "known" attributes from the session, i.e. attributes listed by name in @SessionAttributes or attributes previously stored in the model that matched by type.

hasSessionAttributes

open fun hasSessionAttributes(): Boolean

Whether the controller represented by this instance has declared any session attributes through an SessionAttributes annotation.

isHandlerSessionAttribute

open fun isHandlerSessionAttribute(attributeName: String, attributeType: Class<*>): Boolean

Whether the attribute name or type match the names and types specified via @SessionAttributes on the underlying controller.

Attributes successfully resolved through this method are "remembered" and subsequently used in #retrieveAttributes(WebRequest) and #cleanupAttributes(WebRequest).

retrieveAttributes

open fun retrieveAttributes(request: WebRequest): MutableMap<String, Any>

Retrieve "known" attributes from the session, i.e. attributes listed by name in @SessionAttributes or attributes previously stored in the model that matched by type.

storeAttributes

open fun storeAttributes(request: WebRequest, attributes: MutableMap<String, *>): Unit

Store a subset of the given attributes in the session. Attributes not declared as session attributes via @SessionAttributes are ignored.