2013-11-21 95 views
0

我是playframework的初學者。我的第一個目標是實現一個靜態的html, css, javascript網站,然後添加一些表單等。實施靜態網站進入遊戲

我想只是將代碼粘貼到:

index.scala.html && main.scala.html

我的路由文件看起來像這樣:

# Routes 
# This file defines all application routes (Higher priority routes first) 
# ~~~~ 

# Home page 
GET /      controllers.Application.index() 

我的控制器看起來像這樣:

包控制器;

import play.mvc.Controller; 
import play.mvc.Result; 

public class Application extends Controller { 

    public static Result index() { 
     return TODO; 
    } 

} 

不過,我得到:

enter image description here

我應更改爲just顯示一個HTML頁面?

我很感謝您的回答!

PS:我使用play 2.2.1

UPDATE

我現在試了一下:

package controllers; 

import play.mvc.Controller; 
import play.mvc.Result; 

public class Application extends Controller { 

    public static Result index() { 
     ok(index.render()); 
    } 

} 

不過,我得到一個錯誤:

enter image description here

+2

也許你應該閱讀教程並學習Play中的一些基礎知識。有一個在播放文檔中:http://www.playframework.com/documentation/2.2.x/JavaTodoList – johanandren

+0

@johanandren是的,我看看這個應用程序,但他們正在做,因爲我在我的'更新' 。但是這對我不起作用...... – mrquad

+1

你在第一張圖中請求'/ tasks'。你是否在路線文件中定義了它?到編譯錯誤:檢查你是否在views目錄中有'index'文件。此外,如果你正在使用默認的索引模板,你可能需要傳遞一個字符串到索引函數'ok(index.render(「hello world」));' – 3x14159265

回答

3

你爲什麼要返回TODO?如果你想顯示你的索引模板,讓它返回ok(index.render());

+0

THX很多你的答案!然而,我得到一個錯誤在eclipse索引無法解決...... – mrquad

+1

Eclipse將不會看到它,直到它被編譯到一個類,你已經刷新項目等等,所以我建議你忽略eclipse有關模板的錯誤消息。 – Kayaman

+0

THX爲您的答案!請參閱我的更新...但是,即使在清理我的項目之後,以及在執行「播放運行」之後也不起作用... – mrquad

1

您可以將資產用於靜態內容。

在conf /路線,你犯了一個通用的映射是這樣的:

GET /assets/*file  Assets.at("public", file) 

現在,隨着/資產開始所有請求/會在公共子目錄映射到相同名稱的文件。這甚至會更深層次的嵌套的工作,像/assets/javascript/myapp.js

1

您已刪除的回報,語法是

public static Result index() { 
    return ok(index.render()); 
} 
0

改變你的進口,如下

import play.*; 
import play.mvc.*; 
import views.html.*; 

這將適用於下面的代碼段 ok(index.render());