0
我試圖在Play框架2.5的簡單視圖,但我不斷收到此編譯時錯誤java.util.List<models.Vehicle> cannot be converted to java.lang.String
Play框架:不兼容的類型:java.util.List <models.Vehicle>不能轉換爲java.lang.String
我已經嘗試過this answer
scala.collection.immutable.List<String> ls = JavaConverters.asScalaBufferConverter(scripts).asScala().toList();
但沒有.toList()
功能,它無法識別。 這是我的代碼:
Aplication.java
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
}
}
index.scala.html
@(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>
}
相關的代碼在Vehicle.java
package models;
import javax.persistence.*;
import java.util.List;
@Entity
public class Vehicle extends BaseEntity {
public static Finder<Long, Vehicle> finder = new Finder<Long, Vehicle>(Vehicle.class){};
@Column(nullable = false)
String model;
public String getModel() {
return model;
}
public void setModel(String model) {
this.model = model;
}
}
任何幫助將是非常讚賞。
哦,我得到了,它只需要在項目目錄中執行'clean compile'...我想我只是累了 –