使用Grails进行以下URL映射
'/api/abcdef' (resources: 'abcDef')
'/api/abc' (resources: 'abc')
调用
/api/abcdef
会使用AbcController.index()
而不是format
的def
参数调用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:
- Fewer double wildcards (** or $var**), or if both are equal then
- Fewer single wildcards (* or $var), or if both are equal then
- More non-wildcard path segments, or if both are equal then
- The furthest left wildcard (/foo//baz beats /foo/bar/), or if both have their leftmost wildcard in the same place then
- The one with more constraints
资料来源:https://stackoverflow.com/a/12214694/715608
关于grails - Grails URL映射优先规则,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35738234/