java - Spring MVC + Thymeleaf: adding variable to all templates' context -


how can add "global" variable such username used around template context?

currently setting these explicitly each modelandview object in templatecontroller.

several ways this.

if want add variable views served single controller, can add @modelattribute annotated method - see reference doc.

note can also, using same @modelattribute mechanism, address multiple controllers @ once. that, can implement @modelattribute method in class annotated @controlleradvice - see reference doc.


Comments