【问题标题】: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】:
试试:
<span th:if="${animal.class.name == 'my.project.Cat'}" th:text="A cat"></span>
或者,如果使用 Spring:
<span th:if="${animal instanceof T(my.project.Cat)}" th:text="A cat"></span>
更多关于using SpEL和dialects in thymeleaf的信息。