有没有办法在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>
尝试:
<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>