I would like to know how I can get a User object from Thymeleaf. I am currently calling my userService, which will get the user from the database. I do not like this approach, because a db request will be executed for each call.
Is it possible to get a user from memory?
<link href="/css/style2.css" th:if="${@commanderService.getCurrentCommander()} and ${@commanderService.getCurrentCommander().settings == 'template=1'}" rel="stylesheet" type="text/css" />
CommanderService:
public Commander getCurrentCommander() { Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal(); Commander commander = findByName((String)principal); return commander; }
source share