For loop 简单表达式的非法开始

For loop 简单表达式的非法开始,for-loop,playframework,twirl,For Loop,Playframework,Twirl,我正在尝试使用play执行一个简单的java程序。我得到一个编译错误,因为简单表达式的非法启动。我已经找到了这个问题的答案,但没有找到。我的代码如下所示: @(products :List[Product]) @main("Products catalogue") <h1> All Products </h1> <table class="table table-striped"> <thead> <tr> <th> EAN

我正在尝试使用play执行一个简单的java程序。我得到一个编译错误,因为简单表达式的非法启动。我已经找到了这个问题的答案,但没有找到。我的代码如下所示:

@(products :List[Product])
@main("Products catalogue")
<h1> All Products </h1>
<table class="table table-striped">
<thead>
<tr>
<th> EAN </th>
<th> NAME </th>
<th> DESCRIPTION </th>
</tr>
</thead>
<tbody>
@for(product <- products)
{
<tr>
<td><a href="@routes.Products.details(product.ean)"> @product.ean </a></td>
<td><a href="@routes.Products.details(product.ean)"> @product.name </a></td>
<td><a href="@routes.Products.details(product.ean)"> @product.description  </a></td>
</tr>
}
</tbody>
</table>
@(产品:列表[产品])
@主要(“产品目录”)
所有产品
伊恩
名称
描述

@对于(产品而言,花括号必须与
@for

@for(product <- products){
控制器/Application.java

视图/index.scala.html

@(产品:列表[产品])
所有产品
伊恩
名称
描述
@对于(产品您的视图需要:

@(products :List[Product])
@main("Products catalogue") {
<h1> All Products </h1>
<table class="table table-striped">
<thead>
<tr>
<th> EAN </th>
<th> NAME </th>
<th> DESCRIPTION </th>
</tr>
</thead>
<tbody>
@for(product <- products) {
<tr>
<td><a href="@routes.Products.details(product.ean)"> @product.ean </a></td>
<td><a href="@routes.Products.details(product.ean)"> @product.name </a></td>
<td><a href="@routes.Products.details(product.ean)"> @product.description  </a></td>
</tr>
}
</tbody>
</table>
}
@(产品:列表[产品])
@主要(“产品目录”){
所有产品
伊恩
名称
描述

@为了(产品请为
play framwork
添加标签。因此,相关人员可能会回答您的问题。您需要用大括号将html括起来-从文件的前一段到结尾谢谢。但我在main中遇到了错误,如:在对象main中缺少方法apply的参数;如果要处理此方法,请使用`作为一个部分应用的函数…在用大括号包围html之后。解决方案是什么?请添加您正在得到的错误的屏幕截图,以便我可以进一步帮助您
package controllers;

import play.*;
import play.mvc.*;

import views.html.*;

import models.Product;
import java.util.List;
import java.util.ArrayList;

public class Application extends Controller {

    public Result index() {
        List<Product> products = new ArrayList<>();

        Product product1 = new Product();
        product1.setName("p 1");
        product1.setEan("ean_1");
        product1.setDescription("description 1");

        products.add(product1);
        return ok(index.render(products));
    }

}
# Home page
GET     /                           controllers.Application.index()
@(products :List[Product])
<h1> All Products </h1>
<table class="table table-striped">
<thead>
<tr>
<th> EAN </th>
<th> NAME </th>
<th> DESCRIPTION </th>
</tr>
</thead>
<tbody>
@for(product <- products){
<tr>
<td><a href="@routes.Application.index()"> @product.getEan </a></td>
<td><a href="@routes.Application.index()"> @product.getName </a></td>
<td><a href="@routes.Application.index()"> @product.getDescription  </a></td>
</tr>
}
</tbody>
</table>
<h1> All Products </h1>
<table class="table table-striped">
<thead>
<tr>
<th> EAN </th>
<th> NAME </th>
<th> DESCRIPTION </th>
</tr>
</thead>
<tbody>

<tr>
<td><a href="/"> ean_1 </a></td>
<td><a href="/"> p 1 </a></td>
<td><a href="/"> description 1  </a></td>
</tr>

</tbody>
</table>
@(products :List[Product])
@main("Products catalogue") {
<h1> All Products </h1>
<table class="table table-striped">
<thead>
<tr>
<th> EAN </th>
<th> NAME </th>
<th> DESCRIPTION </th>
</tr>
</thead>
<tbody>
@for(product <- products) {
<tr>
<td><a href="@routes.Products.details(product.ean)"> @product.ean </a></td>
<td><a href="@routes.Products.details(product.ean)"> @product.name </a></td>
<td><a href="@routes.Products.details(product.ean)"> @product.description  </a></td>
</tr>
}
</tbody>
</table>
}