Play Framework:不兼容的类型:java.util.List <models.vehicle>无法转换为java.lang.String

时间:2016-05-22 23:31:23

标签: java scala playframework playframework-2.5

我在Play框架2.5中尝试了一个简单的视图,但我不断收到编译时错误bar

我已经尝试过this answer

java.util.List<models.Vehicle> cannot be converted to java.lang.String

但没有scala.collection.immutable.List<String> ls = JavaConverters.asScalaBufferConverter(scripts).asScala().toList(); 功能,无法识别。 这是我的代码:

Aplication.java

.toList()

index.scala.html

package controllers;

import models.Vehicle;
import play.mvc.Controller;
import play.mvc.Result;
import scala.collection.JavaConverters;

public class Application extends Controller {

    public Result index() {
    //        this does not work
    //        scala.collection.immutable.List<Vehicle> ls = JavaConverters.asScalaBufferConverter(Vehicle.finder.all()).asScala().toList();
              return ok(views.html.index.render(Vehicle.finder.all())); //here is the error
    }

}

Vehicle.java中的相关代码

@(vehicles: java.util.List[Vehicle])

@main("Welcome to Play") {

    <header>
        <hgroup>
            <h1>Dashboard</h1>
            <h2>Vehicles</h2>
        </hgroup>
    </header>

    <ul>
    @for(vehicle <- vehicles) {
        <li>@vehicle.getModel</li>
    }
    </ul>
}

任何帮助都将受到高度赞赏。

1 个答案:

答案 0 :(得分:1)

好的,如果将来有人发现这一点,请尝试

= tonumber(val)

在项目文件夹中。

仅执行activator clean compile 根本没有帮助。