Comparing the enum constants in thymeleaf

前端 未结 10 2051
自闭症患者
自闭症患者 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:08

    I tend to add isXXX() methods to my enums:

    enum Constants {
        ONE,TWO,THREE;
        public boolean isOne() { return this == ONE; }
        public boolean isTwo() { return this == TWO; }
        public boolean isThree() { return this == THREE; }
    }
    

    Then, if value is an instance of your enum, you can use th:if="${value.one}".

提交回复
热议问题