Use Java 5 enumeration as velocity variable

All I need to use Java 5 enumeration in the speed template so that I can write something similar

public enum Level{
    INFO,ERROR;
}

VeLocity template:

#if($var == Level.INFO)
...
#else
...
#end

What should I do? Thank you in advance

Solution

In fact, instead of toString (), it is better to use name (), because it will completely return the enumerated value and is final, so it cannot be overwritten in the future So you can use something similar in speed

#if($var.name() == "INFO")
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>