In Freemarker templates, how do you get the name of the data model's class?
I开发者_运维知识库'm using Freemarker to generate an XHTML page from a POJO which contains a List of Objects, all of which are instances of subclasses of the same parent class. I'd like to generate different information for each object based on its class. How do you test for that in the Freemarker language? For example, if I had a List, how would I determine if a particular Shape was a Rectangle or a Circle?
${class.name}
Though I suggest you consider using a method from each class to generate the unique behavior for each subclass. Polymorphism is a wonderful thing. :)
精彩评论