Skip to content

Latest commit

 

History

History
42 lines (34 loc) · 1.2 KB

File metadata and controls

42 lines (34 loc) · 1.2 KB

@SessionAttribute

If you need access to pre-existing session attributes that are managed globally (that is, outside the controller — for example, by a filter) and may or may not be present, you can use the @SessionAttribute annotation on a method parameter, as the following example shows:

Java
@GetMapping("/")
public String handle(@SessionAttribute User user) { // (1)
	// ...
}
  1. Using @SessionAttribute.

Kotlin
@GetMapping("/")
fun handle(@SessionAttribute user: User): String { // (1)
	// ...
}
  1. Using @SessionAttribute.

For use cases that require adding or removing session attributes, consider injecting WebSession into the controller method.

For temporary storage of model attributes in the session as part of a controller workflow, consider using SessionAttributes, as described in @SessionAttributes.