I know the "pet" object below is stored to session by using @SessionAttributes, but can I use session.getAttribute ? (such as .. Pet pet = (Pet)session.getAttribute("pet")). I am not sure why I do not need a "Session Key". (We have to define the key when using session.setAttribute("id", id))

1 Answer
1

Session attributes configured via @SessionAttributes are intended to be accessed as model attributes rather than by calling methods of Session directly, therefore their names are generated from the model attribute names automatically.

By default, session attribute name is the same as the model attribute name, so you can access it as session.getAttribute("pet") (see DefaultSessionAttributeStore).