0

我是玩2.0.3框架的新手。有没有办法让所有控制器和操作的路由文件中只有一个条目,如下所示:

/{控制器}/{动作} /控制器/动作

  • 控制器将是任何控制器
  • 行动将是任何行动

提前致谢

4

2 回答 2

1

That approach doesn't fit the type safety - main idea of Play 2.0, so it's just suggested to create proper routes for each action also declaring the params with proper types to make sure that every route (also reverse route) always hits the required target action.

Of course you can also write own action for sub-routing where you can catch whole path (Dynamic parts spanning several / ) and manually redirect to some action, however it still requires creating lot of common routes + lot of custom type validation in it etc, etc, so using original router is just faster and cleaner approach.

于 2012-09-04T06:04:31.540 回答
1

为了类型安全(Play 2 中的路由已编译,因此您知道它们在编译时有效),不支持 catch all 路由。

您可以做到的唯一方法是将所有路由发送到单个控制器,然后从该控制器内重定向您的代码,但我认为这不适合您。

于 2012-09-04T06:01:18.447 回答