Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

To remove an attribute from session using Thymeleaf in Spring Boot, you can use the following code:

  1. In the Controller class:
@GetMapping("/removeSessionAttribute")
public String removeSessionAttribute(HttpSession session) {
    // remove the "someAttribute" from session
    session.removeAttribute("someAttribute");
    return "redirect:/home";
}
  1. In the Thymeleaf template:
<a th:href="@{/removeSessionAttribute}" class="btn btn-primary">Remove Attribute</a>

This code will create a link/button, which will call the removeSessionAttribute() method in the controller to remove the specified attribute from session.