Play 2 Scala模板中的编译错误

时间:2015-10-10 16:12:09

标签: scala playframework playframework-2.0 template-engine

我正在尝试运行我的第一个播放应用程序,但似乎我错了。 我得到编译错误 play.api.templates.HtmlFormat.Appendable不接受参数在D:\ PlayProjects \ HelloJava \ app \ views \ index.scala.html

index.scala.html

 @(message: String)(level:Int, list:Seq[String])
    @main("Welcome to Play Framework") {    
        <div class="well">
            <h1>@message</h1>       
            @listContainer{
                <h@level>Level @level </h@level>
                    }(level, list){ //this curly brace is error point
                        <div>footer</div>
                    }
        </div>
    }

listContainer.scala.html

@(header:Html)(level:Int , items:Seq[String]) (footer:Html)
<h@level>Here we go ! </h@level>
<div style="margin-left:@{5*level}%">
    @header
        <ul id="list@level" style="margin-left: @{5*level}%" >
            @items.map {item =>
                <li>@item</li>
                }
        </ul>
    @footer
</div>

编制结果:

classes...
[error] D:\PlayProjects\HelloJava\app\views\index.scala.html:9: play.api.templat
es.HtmlFormat.Appendable does not take parameters
[error]                                 }(level, list){
[error]                                               ^
[error] D:\PlayProjects\HelloJava\app\views\listContainer.scala.html:12: not fou
nd: value footer
[error]         @footer
[error]          ^
[error] two errors found
[error] (compile:compile) Compilation failed
[error] application -

! @6nl63boe5 - Internal server error, for (GET) [/] ->

play.PlayExceptions$CompilationException: Compilation error[play.api.templates.H
tmlFormat.Appendable does not take parameters]
        at play.PlayReloader$$anon$1$$anonfun$reload$2$$anonfun$apply$14$$anonfu
n$apply$16.apply(PlayReloader.scala:304) ~[na:na]
        at play.PlayReloader$$anon$1$$anonfun$reload$2$$anonfun$apply$14$$anonfu
n$apply$16.apply(PlayReloader.scala:304) ~[na:na]
        at scala.Option.map(Option.scala:145) ~[scala-library.jar:na]
        at play.PlayReloader$$anon$1$$anonfun$reload$2$$anonfun$apply$14.apply(P
layReloader.scala:304) ~[na:na]

1 个答案:

答案 0 :(得分:0)

在摆弄我的代码之后我找到了答案:D

@(header:Html)(level:Int , items:Seq[String])(footer:Html)

我删除了“Seq [String])”和(页脚:HTML)之间的空格来修复问题。猜猜参数定义之间不应该有任何空格。