在Thymeleaf中使用instanceof [英] Use instanceof in Thymeleaf
本文介绍了在Thymeleaf中使用instanceof的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有办法在Thymeleaf中使用Java instanceof
运算符?
Is there a way to use the Java instanceof
operator in Thymeleaf?
类似的东西:
<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>
推荐答案
尝试:
<span th:if="${animal.class.name == 'my.project.Cat'}" th:text="A cat"></span>
或者,如果使用Spring:
or, if using Spring:
<span th:if="${animal instanceof T(my.project.Cat)}" th:text="A cat"></span>