开发者

In Freemarker templates, how do you get the name of the data model's class?

开发者 https://www.devze.com 2023-01-24 05:55 出处:网络
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 d

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. :)

0

精彩评论

暂无评论...
验证码 换一张
取 消