玩!框架编译错误 - 未找到:值id

时间:2014-01-21 19:40:37

标签: eclipse scala playframework playframework-2.0

我在Play中使用URI路由!首次。这就是我所拥有的:

  • Eclipse IDE,更新后的恕我直言;

  • 错误:

    Compilation error - not found: value id
    In C:\play\play-2.2.1\samples\java\forms\app\views\contact\form.scala.html at line 7.
    
    
    @import helper.twitterBootstrap._
    
    @title = {
      Add a new contact <small><a href="@routes.Contacts.edit(id: Long)">Or edit an existing contact</a></small> 
    }
    
    @phoneField(field: Field, className: String = "phone") = {
      @input(field, '_label -> "Phone numbers", '_class -> className) { (id, name, value, _) =>
      ...
    
  • 路线:

    GET     /contacts/:id               controllers.Contacts.edit(id: Long)
    
  • 控制器:

    public static Result edit(Long id) {
        Contact existingContact = Contact.find.byId(3L);
        return ok(form.render(contactForm.fill(existingContact)));
    }
    

嗯,那就是它!我还能检查什么?谢谢!

1 个答案:

答案 0 :(得分:2)

当您引用routes.Contacts.edit路线时,您需要传递ID。现在,看起来您只是复制了参数声明(例如id: Long),而不是选择要通过的有意义的ID。

声明您的title阻止接受id作为参数,例如:

@title(id: Long) = {
  Add a new contact <small><a href="@routes.Contacts.edit(id)">Or edit an existing contact</a></small> 
}

然后当你使用它时,传递id,例如:

@title(someId)
相关问题