[英]Is there an “instanceof” functionality in the template engine of the Play framework?
我想知道Play(2.0)框架的模板引擎中是否存在某種instanceof
功能。 這將允許我有效地使用模型層中的繼承結構。
這基本上是我想要的(除了這個模板不能編譯):
@(instance: Superclass)
@main {
@if(instance instanceof Subclass) {
Subclass instanceOfSubclass = (Subclass) instance;
}
}
編輯:我的意思是特定的Play for Java。
使用Scala模式匹配。
@(instance: Superclass)
@main {
@instance match {
case foo: Foo => {
<a href="@routes.Foo.index()">@foo.title</a>
}
case bar: Bar => {
<a href="@routes.Bar.index()">@bar.title</a>
}
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.