【问题标题】:play scala ';' expected but '@' found error at controllers's @Inject()播放斯卡拉';'预期但“@”在控制器的 @Inject() 处发现错误
【发布时间】:2015-07-06 05:31:37
【问题描述】:

我是play scala frame work 的新手,在我的项目中我想为此选择multiple values in drop down 我在select.scala.html 中使用了http://silviomoreto.github.io/bootstrap-select/ 这个插件并添加了所需的.css,.js 文件 select.scala.html

 @import helper._

@(field: play.api.data.Field, options: Seq[(String,String)], args: (Symbol,Any)*)(implicit handler: FieldConstructor, messages: play.api.i18n.Messages)
<html>
<head> 
        <link rel="stylesheet" type="text/css" href="@routes.Assets.at("stylesheets/bootstrap-select.css")">
        <link rel="stylesheet" type="text/css" href="@routes.Assets.at("stylesheets/bootstrap-select.min.css")">
<script type="text/javascript" src="@routes.Assets.at("javascripts/bootstrap-select.js")"></script> 
</head>

@input(field, args:_*) { (id, name, value, htmlArgs) =>
    @defining( if( htmlArgs.contains('multiple) ) "%s[]".format(name) else name ) { selectName =>
    @defining( ( !field.indexes.isEmpty && htmlArgs.contains('multiple) ) match {
            case true => field.indexes.map( i => field("[%s]".format(i)).value ).flatten.toSet
            case _ => field.value.toSet
    }){ values =>
        <select id="@id" name="@selectName" @toHtmlArgs(htmlArgs) class="selectpicker" multiple> 
            @args.toMap.get('_default).map { defaultValue =>
                <option class="blank" value="">@defaultValue</option>
            }
            @options.map { v =>
                <option value="@v._1" @if(values.contains(v._1)){selected="selected"}>@v._2</option>
            }
        </select>
    }}
}
</body>
</html>

Employees.scala controller class

package controllers

import play.api.mvc._
import play.api.data._
import play.api.data.Forms._
import views._
import models._
import play.api.i18n.Messages._

object Employees @Inject()(val messagesApi: MessagesApi)  extends Controller with I18nSupport { 
---
----
}

当我编译我的项目时,它显示以下错误

D:\employee>activator compile
[info] Loading project definition from D:\employee\project
[info] Set current project to employee(in build file:/D:/employee/)
[info] Compiling 37 Scala sources and 1 Java source to D:\employee\target\scala-2.11\classes...
[error] D:\employee\app\controll
ers\Employees.scala:11: ';' expected but '@' found.
[error] object Employees @Inject()(val messagesApi: MessagesApi)  extends Contr
oller   with I18nSupport {
[error]                   ^
[error] one error found
[error] (compile:compileIncremental) Compilation failed please help me to fix this issue.

【问题讨论】:

  • 你在你的项目中看到addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.4.2")里面的project/plugins.sbt是什么版本?
  • 我的plugins.sbt 包含addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.3.9")

标签: scala drop-down-menu playframework playframework-2.3 typesafe-activator


【解决方案1】:

你应该使用类。对象的范围和生命周期与 guice 管理的依赖项不同。

class Employees @Inject()(val messagesApi: MessagesApi)

【讨论】:

  • 如果我使用class Employees @Inject()(val messagesApi: MessagesApi) extends Controller with I18nSupport { ,它会在eclipsenot found: type Injectnot found: type MessagesApinot found: type I18nSupport中显示以下错误
  • 您的导入已损坏。尝试导入 javax.inject.Inject 和其余部分。
  • javax 不包含inject 包,但它有accessibility,annotation,activity,crypto,etc..
  • 显示错误为object inject is not a member of package javax
  • 正如 MonCalamari 所说,您不能注入对象。对象可能会在注入之前被实例化。导入问题很可能与您的项目构建设置或 java/scala 版本有关。你至少错过了这个import play.api.i18n.I18nSupport。使用您的构建文件(如 build.sbt 或 Build.scala)更新您的消息
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-08-22
  • 1970-01-01
  • 2016-10-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多