在Thymeleaf中使用instanceof [英] Use instanceof in Thymeleaf

查看:311
本文介绍了在Thymeleaf中使用instanceof的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法在Thymeleaf中使用Java instanceof运算符?

Is there a way to use the Java instanceof operator in 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>

推荐答案

尝试:

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

或者,如果使用Spring:

or, if using Spring:

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

有关使用SpEL 查看全文

登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆