【问题标题】:Use instanceof in Thymeleaf在 Thymeleaf 中使用 instanceof
【发布时间】:2015-05-01 05:44:55
【问题描述】:

有没有办法在 Thymeleaf 中使用 Java instanceof 运算符?

类似:

<span th:if="${animal} instanceof my.project.Cat" th:text="A cat"></span>
<span th:if="${animal} instanceof my.project.Dog" th:text="A dog"></span>

【问题讨论】:

    标签: java spring spring-boot thymeleaf spring-el


    【解决方案1】:

    试试:

    &lt;span th:if="${animal.class.name == 'my.project.Cat'}" th:text="A cat"&gt;&lt;/span&gt;

    或者,如果使用 Spring:

    &lt;span th:if="${animal instanceof T(my.project.Cat)}" th:text="A cat"&gt;&lt;/span&gt;

    更多关于using SpELdialects in thymeleaf的信息。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-03-18
      • 2011-11-23
      • 2011-09-03
      • 2013-03-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多