我在控制器中有一个函数,它返回用户模型记录的列表--我使用的是PlayStartApp模板:
public Result getAllUsers() {
List<User> users = User.find.all();
return ok(searchusers.render(form(Login.class, users)));
}
此函数工作正常,并返回一个列表对象。
我还设置了一个视图(html页面),用于将对象传递给视图:
@(loginForm: Form[Application.Login], userList: java.util.List[User])
当我在命令行上使用激活器进行编译时,我收到以下错误消息:
[PlayStartApp] $ compile
[info] Compiling 1 Scala source and 1 Java source to C:\WebDev\git\PlayAuthentic
ate\target\scala-2.10\classes...
[error] C:\WebDev\git\PlayAuthenticate\app\controllers\Application.java:209: met
hod render in class views.html.searchusers cannot be applied to given types;
[error] required: play.data.Form<controllers.Application.Login>,java.util.List
<models.User>
[error] found: play.data.Form<controllers.Application.Login>
[error] reason: actual and formal argument lists differ in length
[error] searchusers.render
[error] C:\WebDev\git\PlayAuthenticate\app\controllers\Application.java:215: no
suitable method found for form(java.lang.Class<controllers.Application.Login>,ja
va.util.List<models.User>)
[error] method play.data.Form.<T>form(java.lang.Class<T>,java.lang.Class<?>)
is not applicable
[error] (cannot infer type-variable(s) T
[error] (argument mismatch; java.util.List<models.User> cannot be conver
ted to java.lang.Class<?>))
[error] method play.data.Form.<T>form(java.lang.String,java.lang.Class<T>,ja
va.lang.Class<?>) is not applicable
[error] (cannot infer type-variable(s) T
[error] (actual and formal argument lists differ in length))
[error] method play.data.Form.<T>form(java.lang.String,java.lang.Class<T>) i
s not applicable
[error] (cannot infer type-variable(s) T
[error] (argument mismatch; java.lang.Class<controllers.Application.Logi
n> cannot be converted to java.lang.String))
[error] method play.data.Form.<T>form(java.lang.Class<T>) is not applicable
[error] (cannot infer type-variable(s) T
[error] (actual and formal argument lists differ in length))
[error] form
[info] Some messages have been simplified; recompile with -Xdiags:verbose to get
full output
[error] (compile:compileIncremental) javac returned nonzero exit code
我看了这篇文章,但我仍然有同样的问题:Play Framework 2.2.1 - Compilation error: "method render in class index cannot be applied to given types;"
任何帮助都是最好的!
编辑:我删除了登录表单。代码现在是:
public Result getAllUsers() {
List<User> users = User.find.all();
return ok(searchusers.render(users));
}
我现在的观点是:
@(userList: List[User])
@main(null) {
<ul>
@for(user <- userList) {
<li>@user.fullname</li>
}
</ul>
}
我在编译的时候收到了这个:
[error] C:\WebDev\git\PlayAuthenticate\app\controllers\Application.java:209: no
instance(s) of type variable(s) T exist so that play.data.Form<T> conforms to java.util.List<models.User>
发布于 2016-11-03 19:58:23
更改此行
ok(searchusers.render(form(Login.class, users)))
至
ok(searchusers.render(form(Login.class), users))
为了清楚起见
Form[Application.Login] loginForm = form(Login.class)
ok(searchusers.render(loginForm, users))
您必须将form作为第一个参数传递,将users作为第二个参数传递,但是您试图将Login.class和users传递给form,这是错误的。
https://stackoverflow.com/questions/40410135
复制相似问题