2015-02-28 10 views
9

में उदाहरण का प्रयोग करें क्या Thymeleaf में जावा 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> 

उत्तर

16

प्रयास करें:

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

या, स्प्रिंग का उपयोग कर यदि:

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

using SpEL औरके बारे में अधिक 210।

+1

धन्यवाद! दोनों संस्करण महान काम करता है! – Andrea

संबंधित मुद्दे