【问题标题】:play framework 2.0 reverse routingplay framework 2.0 反向路由
【发布时间】:2013-04-17 00:50:27
【问题描述】:

我是 Java 新手,我正在为一个项目使用 play framework 2.0,并且想知道如何使用反向路由功能。我们有以下内容:

在路由文件中

GET /                controllers.Application.index()
GET /myapp/storage   controllers.myapp.AnotherController.index()

所以要使用反向路由:

controllers.routes.ref.Application.index() 

但是AnotherController 呢?

如果我在测试中使用controllers.routes.ref.AnotherController.index(),播放框架会抛出错误“找不到符号”。

谢谢。

【问题讨论】:

  • 为什么不把您的 AnotherController.java 也放在 app.controllers 包中?
  • 我希望将控制器分组到单独的包中。当使用定义的路由“GET /test controllers.myapp.AnotherController.index()”发出 GET 请求时,播放框架解决了它没有问题。所以我希望反向路由也适用于这种设置。
  • 你试过ontrollers.routes.ref.myapp.AnotherController.index() 吗?
  • 是的,我尝试了 controllers.routes.ref.myapp.AnotherController.index() 并报告找不到符号 myapp。 avik 建议的效果非常好...... controllers.myapp.routes.AnotherController.index.

标签: playframework-2.0


【解决方案1】:

尝试删除ref 元素。我在 play-2.0.4 应用程序中使用以下结构进行反向路由:

<full-package-name>.routes.<controller>.<action>

因此,您的第二个操作的反向路线将是:

controllers.myapp.routes.AnotherController.index()

鉴于您的操作不带参数,我想您也可以去掉括号:

controllers.myapp.routes.AnotherController.index

【讨论】:

  • 感谢 avik.. 工作完美!!
【解决方案2】:

这种方式对我有用。我不知道为什么:

activator clean
activator run

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-04-09
    • 1970-01-01
    相关资源
    最近更新 更多