Use instanceof in Thymeleaf

前端 未结 1 1150
天命终不由人
天命终不由人 2021-02-13 14:23

Is there a way to use the Java instanceof operator in Thymeleaf?

Something like:



        
相关标签:
1条回答
  • 2021-02-13 15:01

    Try:

    <span th:if="${animal.class.name == 'my.project.Cat'}" th:text="A cat"></span>

    or, if using Spring:

    <span th:if="${animal instanceof T(my.project.Cat)}" th:text="A cat"></span>

    more about using SpEL and dialects in thymeleaf.

    0 讨论(0)
提交回复
热议问题