Play Framework Cookbook (play框架食譜...)

Play Framework Cookbook
Play框架食譜
over 60 incredibly effective recipes to take you under the hood and leverage advanced concepts of the play framework
有60個實際例子(一步一步手把手教)幫助你更好的掌握playframework(感謝羣裏的冷豔灰)


ch1基礎

using controllers
ch2使用控制器
URL routing using annotation-based configuration
路由使用“基於註解”的配置
if you do not like the routes files,you can also describe your routes programmatically by adding annotation to your controllers.This has the advantage of not having any additional config file,but also poses the problem of your URLs being dispersed in your code.
要是你不喜歡routes(路由)文件,你可以給controllers(控制器)添加註釋來描述你的路由。這樣做的好處沒有任何額外的配置文件,但也引出了一個問題,你的url(網絡地址)被分散在你的代碼中。
How to do it
怎樣做...
Go to your project and install the router module via conf/dependencies.yml:
打開你的項目,配置conf/dependencies.yml文件安裝路由器模塊:(譯者注:反正我在用play-1.0.3.2無此配置文件,其它版本也許有)
dependencies.yml中輸入以下內容:
require:
-play
-play -> router head
Then run playdeps and the router module should be installed in the modules/directory of your application. Change your controller like this:
@StaticRoutes({
@ServeStatic(value="/public/", directory="public")
})
public class Application extends Controller{
@Any(value="/",priority=100)
public static void index(){
forbidden("Reserved for administrator");

}
@put(value="/",priority=2, accept="application/json")
public static void hiddenIndex(){
rederText("Secret news here");
}
@post("/ticket")
public static void getTicket(String username,String password){
String uuid = UUID.randomUUID().toString();
renderJSON(uuid);
}
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章