1 | initial version |
To remove an attribute from session using Thymeleaf in Spring Boot, you can use the following code:
@GetMapping("/removeSessionAttribute")
public String removeSessionAttribute(HttpSession session) {
// remove the "someAttribute" from session
session.removeAttribute("someAttribute");
return "redirect:/home";
}
<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.