【问题标题】:Checking If-Else in Thymeleaf在 Thymeleaf 中检查 If-Else
【发布时间】:2014-02-21 07:14:39
【问题描述】:

我是 thymeleaf 的新手,想将以下 Jsp 代码转换为 Thymeleaf。我不知道如何处理 if else using 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>

谁能帮我把它转换成百里香格式?

【问题讨论】:

标签: java html spring jakarta-ee thymeleaf


【解决方案1】:
<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

【讨论】:

    猜你喜欢
    • 2021-11-25
    • 2012-11-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-07-07
    • 2023-04-02
    • 1970-01-01
    相关资源
    最近更新 更多