Scala&Play:没有标识符的路由正则表达式

Ric*_*nka 7 regex scala playframework-2.0

我想在Play应用程序中为我的路线提供可选的多个.例如:

/path/1
/paths/1
Run Code Online (Sandbox Code Playgroud)

我试过的路由网址是这样的:

/path<[s?]>/:id
Run Code Online (Sandbox Code Playgroud)

如果我只在它前面放一个$,它会要求一个标识符; 如果我给它一个标识符,它告诉我我需要在调用定义中使用它.我是否正在努力做到这一点,而不必做每个可能带/多组合的笛卡尔积?

Nic*_*tot 5

如果我对RoutesCompiler 的理解是正确的(尤其是check函数),那么在调用定义中必须使用URL 中的任何动态部分。

所以看起来唯一的选择是添加一个像这样的新参数:

GET    /$p<paths?>/:id         controllers.PathController.get(p, id)
GET    /otherpath$p<s?>/:id    controllers.OtherController.get(p, id)
Run Code Online (Sandbox Code Playgroud)

然后只需忽略该p参数。但是,在使用反向路由时,您需要提供它。