1
votes

I am new to thymeleaf and would like to convert the following Jsp code to Thymeleaf. I don't know how to deal with if else using thymeleaf.My jsp page looks similar to this:

index.jsp

<div id="header">
  <% if(${variable1}==null){%>
    <a href="/home">Enter Here</a>
    <br><a href="/signUp">Signup Here</a>
  <% }else if(${variable}=="Guest"){%>
     <p>Hello Guest</p>
     <br><a href="play">Play game</a>
   <% } else { %>
     <p> Enter ${variable}</p>
     <a href="play">Play game</a>

</div>

Can anyone help me in converting this in thymeleaf format?

1

1 Answers

1
votes
<div th:switch="${user.role}">
  <p th:case="'admin'">User is an administrator</p>
  <p th:case="#{roles.manager}">User is a manager</p>
</div>

Taken from Thymeleaf Documentation http://www.thymeleaf.org/doc/html/Using-Thymeleaf.html#simple-conditionals-if-and-unless