如何将对象发送到 Scala 视图中
我已经编写了这些文件,当我尝试构建它们时,我收到了这个错误,这在底部进行了描述
应用程序/视图/时间线/index.scala.html
@(token: models.Token)
<!DOCTYPE html>
<html>
<head>
</head>
<body>
Hello Mr @{token.name}
</body>
</html>
应用程序/控制器/TimeLine.java
public class TimeLine extends Controller {
public static Result index() {
Token token = new Token();
token.name("NInjaaa");
return ok(views.html.timeline.index.render(token)); //I dont know how to send it...
}
}
应用程序/模型/Token.java
package models;
import play.db.ebean.Model;
public class Token extends Model{
/**
*
*/
private static final long serialVersionUID = 5629541435986605754L;
public String name;
}
编译时收到此错误消息
[error] /Users/fbranchetti/Dropbox/webproject/timeline/app/controllers/TimeLine.java:17: cannot find symbol
[error] symbol : method name(java.lang.String)
[error] location: class models.Token
[error] token.name("NInjaaa");
[error] ^
[error] /Users/fbranchetti/Dropbox/webproject/timeline/app/controllers/TimeLine.java:18: render() in views.html.timeline.index cannot be applied to (models.Token)
[error] return ok(views.html.timeline.index.render(token));
[error] ^
[error] 2 errors
[error] {file:/Users/fbranchetti/Dropbox/webproject/timeline/}TimeLine/compile:compile: javac returned nonzero exit code