Use instanceof in Thymeleaf

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-04 18:07:39

问题


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

Something like:

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

回答1:


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.



来源:https://stackoverflow.com/questions/28783272/use-instanceof-in-thymeleaf

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!