Используйте instanceof в Thymeleaf

Есть ли способ использовать оператор Java instanceof в 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>

person Andrea    schedule 28.02.2015    source источник


Ответы (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>

подробнее об использовании SpEL и диалекты в тимелеафе.

person Trynkiewicz Mariusz    schedule 28.02.2015