传递arraylist时在scala模板中编译错误:未找到值

Paw*_*wan 4 scala playframework

我试图将一个arraylist传递给一个播放控制器的scala模板.

在我的控制器中

List<Profile> profiles = Profile.findAll();

return ok(contacts.render(profiles));
Run Code Online (Sandbox Code Playgroud)

在模板contacts.scala.html中

@import models.com.contactmanager.Profile
@(profiles: List[Profile])
Run Code Online (Sandbox Code Playgroud)

我收到错误:

not found: value profiles [error] 
Run Code Online (Sandbox Code Playgroud)

换行

@(profiles: List[Profile])
Run Code Online (Sandbox Code Playgroud)

Sch*_*rdt 7

在Scala模板的参数列表中,您必须使用(a)完全限定的类名或(b)在Build.scala中导入它们.

(一个)

@(profiles: List[models.com.contactmanager.Profile])
Run Code Online (Sandbox Code Playgroud)

(b)中

//Play 2.2
val main = PlayProject(…).settings(
  templatesImport += "models.com.contactmanager.Profile"
)
Run Code Online (Sandbox Code Playgroud)

对于Play 2.3,API已更改:https: //www.playframework.com/documentation/2.3.x/ScalaTemplates#Import-statements

TwirlKeys.templateImports += "models.com.contactmanager.Profile"
Run Code Online (Sandbox Code Playgroud)