玩Scala:课程需要抽象

时间:2016-04-04 07:13:28

标签: scala playframework

我是Scala中Play的初学者,当我想打开我的应用时收到此错误:

class ElevesController needs to be abstract, since method messagesApi in trait I18nSupport of type => play.api.i18n.MessagesApi is not defined

EleveController.scala

package controllers

import javax.inject.Inject
import play.api.Logger
import play.api.data.Form
import play.api.data.Forms._
import play.api.i18n.{Messages, I18nSupport, MessagesApi}
import play.api.mvc.{Action, Controller}
import views.html
import scala.concurrent.Future
import models.Eleve

class ElevesController @Inject() extends Controller with I18nSupport {


  def viewEleves = Action {implicit request =>
    Ok(html.viewseleves(Eleve.findAll))
  }
}

我不知道如何解决它

编辑: 我解决了,我只需要添加:"(val messagesApi:MessagesApi)"在这一行:

    class ElevesController @Inject()(val messagesApi: MessagesApi) extends Controller with I18nSupport {

1 个答案:

答案 0 :(得分:2)

这应该有效。只需改变你的行动等。

https://playframework.com/documentation/2.4.0-RC2/api/scala/index.html#play.api.i18n.I18nSupport

               package controllers

               import javax.inject._
               import play.api._


                import javax.inject.Inject
                import play.api.Logger
                import play.api.data.Form
                import play.api.data.Forms._
                import play.api.mvc._
                import views.html
                import scala.concurrent.Future
                import play.api.i18n._

                  @Inject() 
                class ElevesController (val messagesApi: MessagesApi)  extends Controller   with I18nSupport {

                   val action = Action { implicit request =>
                    Ok("Ok") // Uses the client???s preferred language
                       }

                    }