簡體   English   中英

Play框架的模板引擎中是否存在“instanceof”功能?

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM