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);
}
}
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);
}
}