Comparing the enum constants in thymeleaf

前端 未结 10 2050
自闭症患者
自闭症患者 2021-02-02 06:25

I have an enum, Constants:

enum Constants {
    ONE,TWO,THREE;
}

How can I compare the enum Constants in Thymeleaf.

Thank

10条回答
  •  迷失自我
    2021-02-02 07:21

    One more way:

    th:if="${constant.name() == 'ONE'}"
    

    It's shorter but makes compare with string representation, can cause problem while refactoring.

提交回复
热议问题