方法的缺少参数适用... Play Framework 2.4编译错误 [英] missing arguments for method apply... Play Framework 2.4 compilation error

查看:137
本文介绍了方法的缺少参数适用... Play Framework 2.4编译错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

编译错误:方法的缺少参数适用于类newPost; 如果要将其视为部分应用的函数,请在此方法后加上"_"

Compilation error: missing arguments for method apply in class newPost; follow this method with `_' if you want to treat it as a partially applied function

我不了解模板处理方法的外观以及编译器对我的要求.
https://github.com/flatlizard/blog

I don't understand how template handling methods have to look like and what complier require of me.
https://github.com/flatlizard/blog

控制器:

  def addPost = Action{ implicit request =>
    Ok(views.html.newPost(postForm))
  }

  def createPost = Action { implicit request =>
    postForm.bindFromRequest.fold(
      hasErrors => BadRequest,
      success => {
        Post.create(Post(new Date, success.title, success.content))
        Ok(views.html.archive("my blog", Post.all))
      })
  }

路线:

GET        /archive/new         controllers.Application.addPost
POST       /archive             controllers.Application.createPost

视图:

@(postForm: Form[Post])(content: Html)(implicit messages: Messages)
@import helper._

@form(routes.Application.createPost) {
    @inputDate(postForm("date"))
    @textarea(postForm("title"))
    @textarea(postForm("content"))
    <button id="submit" type="submit" value="Submit" class="btn btn-primary">Submit</button>
}

更新

我解决了在控制器文件中添加以下导入的问题:

I solved problem adding the following imports in controller file:

import play.api.i18n.Messages.Implicits._
import play.api.Play.current

请参阅Play 2.4迁移: https://www.playframework.com/documentation/2.4.x/Migration24#I18n

See Play 2.4 migration: https://www.playframework.com/documentation/2.4.x/Migration24#I18n

推荐答案

我解决了在控制器文件中添加以下导入的问题:

I solved problem adding the following imports in controller file:

import play.api.i18n.Messages.Implicits._
import play.api.Play.current

请参阅Play 2.4迁移: https://www.playframework.com/documentation /2.4.x/Migration24#I18n

See Play 2.4 migration: https://www.playframework.com/documentation/2.4.x/Migration24#I18n

更新

实际上这是一种不好的方法,因为此处使用的Play.current很快就会被弃用.这里是使用依赖注入的另一种解决方案:

Actually this is a bad way cause here used Play.current which will become deprecated soon. Here another solution using dependency injection:

路线:

GET        /archive/new         @controllers.Application.addPost
POST       /archive             @controllers.Application.createPost

控制器:

class Application @Inject() (val messagesApi: MessagesApi)
  extends Controller with I18nSupport{
 ...
}

https://www.playframework.com/documentation/2.4.x/ScalaDependencyInjection

这篇关于方法的缺少参数适用... Play Framework 2.4编译错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆