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);
}
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值