samedi 21 mars 2015

Spring MVC: how can I re-load the logged-in user information from the database on each Thymeleaf page?

I'd like to show some information about the logged-in user in the header of my web site (so they should be available on each page that includes the header).


This information can change in the database and should be re-loaded when the user reload the page.


I wish there was a global object (e.g. loggedInUser), loaded from the database when a Thymeleaf page is returned from the server, so that I can access that object from Thymeleaf without having to pass it from each controller.


Is it possible to achieve something like that?


**** UPDATE ****


For example: I want to show notifications for the user in the header bar and these notifications can be added in the database server-side by various actions. When the user loads any page of the web site (that includes the header) notifications should be loaded server-side and shown in the header from Thymeleaf.


I would like to avoid to load the logged user in order to pass it to Thymeleaf on each controller serving a page.


Aucun commentaire:

Enregistrer un commentaire