Thymeleaf比较判断枚举类型

目录
  1. 问题
  2. 解决办法

问题

使用Thymeleaf试图比较、判断枚举类型

1
2
<span th:if="${source.sourceType == 0}>test</span>
<span th:if="${source.sourceType == 'MOVIE'">test</span>

以上两种方式均不能成功

解决办法

1
2
3
<span th:if="${source.sourceType.name() == 'MOVIE'}>test</span>
// 或
<span th:if="${source.sourceType == T(me.gelu.SourceType).MOVIE}">test</span>

Thymeleaf相关链接:

Thymeleaf List指定数量循环
Thymeleaf SAXParseException
Thymeleaf实现页面静态化
Thymeleaf TemplateProcessingException