java - 检查 Thymeleaf 中的 If-Else

标签 java html spring jakarta-ee thymeleaf

我是 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/

相关文章:

html - 为什么我不能居中呢?

html - 从超链接打开 Access 表单

java - 什么会导致 Play 模块被加载两次?

java - 如何从 JBoss 写入远程 JMS 队列

Java - 按字典顺序查找下一个单词

html - 使用 CSS 对齐登录表单(带有错误文本)

用于类的特定属性的 Spring/Grails 自定义属性编辑器

Spring Data Repository 异步保存

java - 使用 Spring 从 Controller 层调用存储库和服务

java - 链表在位置添加