在Thymeleaf中使用instanceof

And*_*rea 13 java spring spring-el thymeleaf spring-boot

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

就像是:

<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>
Run Code Online (Sandbox Code Playgroud)

Try*_*usz 24

尝试:

<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>

更多关于在百里香中使用SpEL方言的信息.