[英]actual argument List<<anonymous Callable<String>>> cannot be converted to List<Callable<String>> by method invocation conversion
[英]Actual List cannot be converted to String on method invocation conversion
我是一个新手,已经开始开发应用程序以从数据库中获取数据。
我的应用程序中包含以下代码:
public static Result list() {
List products = Productslist.getListOfProducts();
return ok(index.render(products));
}
这给了我以下错误:
Actual List cannot be converted to String on method invocation conversion
您也可以查看我的index.scala.html
#{extends 'main.html' /}
#{set title:'Cars in the car lot' /}
<h1>Products in Lot</h1>
<table border=1>
<tr>
<td>productname</td>
<td>Quantity</td>
<td>Price</td>
</tr>
#{list items:products, as:'product'}
<tr>
<td>${product.getProductname()}</td>
<td>${product.getQuantity()}</td>
<td>${product.getPrice()}</td>
</tr>
#{/list}
</table>
Application.java的完整代码是:
package controllers;
import play.*;
import play.mvc.*;
import models.Productslist;
import views.html.*;
import views.*;
import java.util.*;
public class Application extends Controller
{
public static Result list()
{
List products = Productslist.getListOfProducts();
return ok(index.render(products));
}
}
谁能帮助我找到错误的根源?
好像在index.render(products)上发生了错误; 其中方法render需要一个字符串,但我们正在传递列表。 您可以输入方法render()的代码吗
看起来您为视图使用了错误的代码。 试试这个
@(products: List[Productslist])
@import helper._
@main("Product list") {
<h1>@product.size() product(s)</h1>
<ul>
@for(product <- products) {
<li>
@product.name
</li>
}
</ul>
}
在运行服务器之前,先使用play clean-all
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.