1
如何將對象發送到斯卡拉視圖如何將對象發送到斯卡拉視圖
我已經寫了這些文件,當我嘗試建立他們,我得到這個錯誤,那就是在底部
描述應用/視圖/時間軸/ 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
它現在的投訴,因爲我沒有一個setter和getter的看法。 – Nolaeh 2012-07-27 13:17:28
Och我重寫了你的錯誤,它應該是:'token.name =「Some String」;' – biesior 2012-07-27 13:23:08