一个带有两个控制器的路由
Posted
技术标签:
【中文标题】一个带有两个控制器的路由【英文标题】:One route with two controllers 【发布时间】:2015-07-13 11:29:31 【问题描述】:我想使用一个 url 与不同的查询参数,将由不同的控制器处理:
GET /areas controllers.Application.getXTree(from: String, to: String)
GET /areas controllers.Application.getChildren(parentId:String)
现在我有第二条路线的错误:
对于请求 'GET /areas?parentId=f785d5cc-c8f7-4ddf-a611-757c8f91f536' [缺少参数:来自]
可以这样做吗?
【问题讨论】:
【参考方案1】:不,不可能:
许多路由可以匹配同一个请求。如果存在冲突,则使用第一条路线(按声明顺序)。 Routing-priority
试试这个:
GET /areas/:from/:to controllers.Application.getXTree(from: String, to: String)
GET /areas/:parentId controllers.Application.getChildren(parentId:String)
你也可以用
GET /areas/*params controllers.Application.xTreeOrChildren(params)
然后通过Application.xTreeOrChildren
解析params
,但我更喜欢第一种解决方案。
更多信息请参见ScalaRouting。
【讨论】:
我不想以这种方式更改 url 的逻辑,它会破坏 REST url 规则(GET /areas/:id - 意味着获取有关 id = 的一个区域的信息: ID)。是的,第二个解决方案是有效的。我尝试了Srid router,但是我在这种方式中遇到了一些其他的困难,但这是可能的。以上是关于一个带有两个控制器的路由的主要内容,如果未能解决你的问题,请参考以下文章