我正在开发一个网站,并在此过程中使用springboot和thymeleaf。问题是我似乎无法在登录时显示注销按钮。但是,当我未注销时却显示了登录名。我有两种类型的用户-用户和管理员。登录和注销应适用于两种类型的用户。以下是我用于html中登录和注销的代码。我还附上了控制器中的物品。谢谢menu.html和mycontroller.java
<a th:if="${userRole == 'null'}">
<button type="button" class="btn btn-dark m-2">Logout</button>
</a>
<a th:unless="${userRole == 'null'}">
<button type="button" class="btn btn-dark m-2">Login</button>
</a>
private void setUpNavBar(Model model) {
String presentUserRole;
if (userSession.getUser() == null) presentUserRole = "noUser";
else presentUserRole = userSession.getUser().getRole();
model.addAttribute("userRole",presentUserRole);
System.out.println("setting up navigation bar:" + presentUserRole);
}