grails - Grails URL映射优先规则

标签 grails url-routing

使用Grails进行以下URL映射

'/api/abcdef' (resources: 'abcDef')
'/api/abc' (resources: 'abc')

调用/api/abcdef会使用AbcController.index()而不是formatdef参数调用AbcDefController。但是,将/api/abcdef/1调用正确解析为AbcDefController.show()。看起来像grails url-mapping-report会报告的错误
|   GET    | /api/abcdef                                      | Action: index    |

AbcDefController下。

但是,如果将两个URL的顺序更改为
'/api/abc' (resources: 'abc')
'/api/abcdef' (resources: 'abcDef')

Grails可以将/api/abcdef正确解析为AbcDefController.index()

但无论哪种情况,/api/abc123都将使用AbcController.index()format参数解析为123
URL映射优先级的机制是什么?以上行为对吗?我使用Groovy 2.4.5和Grails 2.5.3。

最佳答案

[W]hen two mappings could apply to the same incoming URI, the one that wins is the one that has:

  1. Fewer double wildcards (** or $var**), or if both are equal then
  2. Fewer single wildcards (* or $var), or if both are equal then
  3. More non-wildcard path segments, or if both are equal then
  4. The furthest left wildcard (/foo//baz beats /foo/bar/), or if both have their leftmost wildcard in the same place then
  5. The one with more constraints


资料来源:https://stackoverflow.com/a/12214694/715608

关于grails - Grails URL映射优先规则,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35738234/

相关文章:

url - 基于用户名的 URL

url-routing - 路由可以以变量开头吗?

javascript - 从 vanilla JS 调用 React Router

php - 如何使用 FastRoute?

unit-testing - Grails 单元测试 : error while redirecting to an action of another controller

Grails 从 config.groovy 中访问当前环境

apache - 将运行时参数传递给 tomcat 服务器上的 grails 项目

grails - grails neo4j插件获取bean错误

ruby-on-rails - 使用:method => delete in button_to?的目的是什么

grails - 初始化高速缓存导致 “grails run-app”失败时发生异常