Playframework 2:是否可以在conf/routes中使用表达式?

Playframework 2:是否可以在conf/routes中使用表达式?,routes,playframework-2.0,Routes,Playframework 2.0,有没有办法在conf/routes中包含表达式,这样我就不必为这些简单的操作创建新的控制器 GET /:id/:secret controllers.Default.redirect(to=id+"/edit?secret="+secret) 不,但你真的只需要一条路线和一种行动方法就可以完成你想要的 conf/routes GET /redirect/:id/:secret controllers.Default.redirect(id:String, secret:String)

有没有办法在conf/routes中包含表达式,这样我就不必为这些简单的操作创建新的控制器

GET /:id/:secret  controllers.Default.redirect(to=id+"/edit?secret="+secret)

不,但你真的只需要一条路线和一种行动方法就可以完成你想要的

conf/routes

GET /redirect/:id/:secret   controllers.Default.redirect(id:String, secret:String)
Default.java

public static Result redirect(String id, String secret)
{
  return redirect(id + "/edit?secret=" + secret);
}

仔细查看中的管线类型,很可能您可以使用跨越多个/的ie动态部件

例如,此函数将以单个字符串形式传递
/redirect/
之后的所有内容:

GET  /redirect/*targetPath   controllers.Application.redirectTo(targetPath:String)
所以在请求中
http://localhost/redirect/new/location/123?secret=foo&something=bar
其值将为:
new/location/123?secret=foo&something=bar

或者,您甚至不需要将您的
secret
声明为路由参数,因为您可以使用ie.
bindFromRequest()
方法来检查它是否存在。(因此它可以与
PHP中的
$\u GET['secret']
进行比较