How to display current logged-in user's information in all templates including view managed by WebMvcConfigurerAdapter in Spring Security application

前端 未结 8 1912
眼角桃花
眼角桃花 2020-12-14 13:02

I have a Spring Boot application that uses Spring Security and Thymeleaf template. I am trying to display the logged-in user\'s first name and last name in a template when t

8条回答
  •  既然无缘
    2020-12-14 13:53

    For thymleaf 4 and above you have to modify some classes in order to get the info. Heres how you can do that:

    First, add the getter of your user getUser(){return this.user;} in the UserDetails class and then push that object in the UserDetailsService object. Without these changes, thymleaf will not parse your HTML file.

    Then you can get the info as follows:

提交回复
热议问题