thymeleaf check code example
Example: thymeleaf, checking if context variable exists
<div th:if="${currentUser}">
<h3>Name:</h3><h3 th:text="${currentUser.id}"></h3>
<h3>Name:</h3><h3 th:text="${currentUser.username}"></h3>
</div>
<div th:if="${currentUser}">
<h3>Name:</h3><h3 th:text="${currentUser.id}"></h3>
<h3>Name:</h3><h3 th:text="${currentUser.username}"></h3>
</div>