Search⌘ K
AI Features

Thymeleaf Integration

Explore how to use Thymeleaf together with Spring Security to tailor user interfaces based on roles. Learn to hide or show buttons and links depending on user permissions and how to display logged-in user information such as username and roles. This lesson helps you implement role-based content rendering in Spring Boot apps.

User-specific views

To improve the user experience, we should hide any buttons, links, or other content that the logged-in user is not supposed to see. To do that, we can use the Thymeleaf Spring Security integration.

Let’s start by adding the needed dependency in pom.xml:

XML
<dependencies>
...
<dependency>
<groupId>org.thymeleaf.extras</groupId>
<artifactId>thymeleaf-extras-springsecurity5</artifactId>
</dependency>
...
</dependencies>

We’ll also edit templates/users/list.html to take the current user role into account when rendering the ...