Java – how to access enum field in playframework template
•
Java
I have an enum, which has some fields that I need in play1 2.4 access in template
public Enum WORKER{ FARMER,SMITH,GARDENER }
Suppose I need to check whether the "person" variable in the template is a farmer, Smith or gardener, what should I do?
#{if person.Type==WORKER.FARMER} ...do something... #{/if}
I'm coming.
NullPointerException : Cannot get property 'FARMER' on null object.
Therefore, the template does not know enum worker Because I can't create a new instance of enum, how can I make enum available for templates?
Solution
Use the absolute class name of enumeration in the template
#{if person.Type == model.myenums.WORKER.FARMER} ...do something... #{/if}
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
二维码