我是 thymeleaf 的新手,想将以下 Jsp 代码转换为 Thymeleaf。我不知道如何处理 if else 使用 thymeleaf。我的 jsp 页面看起来与此类似:
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>
有人可以帮我将其转换为 thymeleaf 格式吗?
最佳答案
<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>
取自 Thymeleaf 文档 http://www.thymeleaf.org/doc/html/Using-Thymeleaf.html#simple-conditionals-if-and-unless
关于java - 检查 Thymeleaf 中的 If-Else,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20497509/