Използвайте 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 и диалекти в thymeleaf.

person Trynkiewicz Mariusz    schedule 28.02.2015