I have an enum, Constants
:
enum Constants { ONE,TWO,THREE; }
How can I compare the enum Constants in Thymeleaf.
Thanks.
There are two ways for making comparison of enum members :equals method uses == operator internally to check if two enum are equal. This means, You can compare Enum using both == and equals method.
To compare with an enum constant, use the following code:
th:if="${day == T(my.package.MyEnum).MONDAY}"
One more way:
th:if="${constant.name() == 'ONE'}"
It's shorter but makes compare with string representation, can cause problem while refactoring.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With