我想知道,我如何能從Thymeleaf獲得用戶對象。目前我正在調用我的userService,它將從DB獲取用戶。我不喜歡這種方法,因爲每次調用db查詢都會進行。春季開機+百里香:獲取登錄用戶
是否有可能從內存中獲取用戶?
<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;
}
你有機會獲得本金'RequestMappingMethod' – 2014-12-02 18:18:38
您是否使用自定義的UserDetailsService?如果是這樣,你能提供你的實施? – 2014-12-03 15:55:48
羅伯特:是的,但它的空 - 它只有findUserByName方法返回null – 2014-12-03 17:59:13