【问题标题】:Does play framework support Nested routes like rails?播放框架是否支持像 rails 这样的嵌套路由?
【发布时间】:2012-06-27 18:44:33
【问题描述】:

Rails 可以映射在逻辑上属于其他资源的子资源的资源,例如在 URL 中

/magazines/:magazine_id/ads/:id show    display a specific ad belonging to a specific magazine

是否可以在游戏中执行此操作?

【问题讨论】:

    标签: playframework routes url-routing playframework-2.0


    【解决方案1】:

    是的,这是可能的。它在你的路由文件中应该是这样的:

    GET   /magazines/:magazine_id/ads/:id/show   controllers.MyController.show(magazine_id: Long, id: Long)  
    

    在你的控制器中

    public static Result show(Long magazine_id, Long id) {
        ...
    }
    

    【讨论】:

      【解决方案2】:

      Play 不在乎参数是否代表某种关系,这是控制器的工作。

      当然可以这样做:

      GET /some/:parent/:child   controllers.Application.getRelated(parent: Long, child: Long)
      

      在控制器中:

      public static Result getRelated(Long parent, Long child) {
          return ok(SomeFinder(parent,child));
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2016-04-30
        • 1970-01-01
        • 1970-01-01
        • 2020-10-23
        • 2018-04-08
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多