玩框架初学者。 Scala.html 编译错误

Play Framework beginner. Scala.html error in compilation

我正在学习 Play 框架,我正在学习 CRUD 控制器。我想制作一个表格来添加新帖子,但我有一个编译错误。由于我是 scala 的新手,所以我无法找出错误。

@(productForm: Form[Product])
@import helper._
@import helper.twitterBootstrap._

@main("Product Form"){
<h1>Product Form</h1>

@helper.form(action = routes.Products.save()){
    <fieldset>
        <legend>Product (@productForm("name").valueOr("New")) </legend>
        @helper.inputText(@productForm("ean"), '_label -> "EAN")
        @helper.inputText(@productForm("name"), '_label -> "Name")
        @helper.textarea(@productForm("description"), '_label -> "Description")
    </fieldset>

    <input type="submit" class="btn btn-primary" value="Save">
    <a class="btn" href="@routes.Products.index()">Cancel</a>
}
}

错误是:

/Users/andrei/Desktop/PlayFramework/app/views/products/details.scala.html:11: illegal start of simple expression
[error]             @helper.inputText(@productForm("ean"), '_label -> "EAN")

另一个problem:I在class中定义了一个private static final变量,但是我得到一个错误。我认为这是由于库已弃用,因为我正在从 2014 年的书中学习框架

import play.api.data.Form; 
import play.api.FormFactory;
public class Products extends Controller {

Form<Product> productForm = formFactory.form(Product.class);

错误:

cannot find symbol
symbol:   variable formFactory
location: class controllers.Products

来源到我找到 FormFactory 的文档: https://www.playframework.com/documentation/2.5.x/JavaForms

因为你用 @ 开始表达式,所以你不需要在 productForm 之前使用它,所以

@helper.inputText(productForm("ean"), '_label -> "EAN")

应该能帮到你。

The Scala template uses @ as the single special character. Every time this character is encountered, it indicates the beginning of a dynamic statement. You are not required to explicitly close the code block - the end of the dynamic statement will be inferred from your code: