我知道可以这样做:
带有操作栏的 Controller foo可以通过(1)访问:
/appname/foo/bar
并且可以使用URL映射进行重写-例如:
"/foobar/foo/$action"(controller: "foo")
然后通过(2)进行访问:
/appname/foobar/foo/bar
但是仍然可以通过(1)访问它。这当然是由于默认的URL映射:
"/$controller/$action?/$id?"()
但是我宁愿不删除它,因为这基本上意味着我必须手动将映射写入遵循默认模式的每个其他 Controller / Action 。
是否可以在不使用URL映射的情况下为特定的 Controller / Action (如(2))获取url模式?如果不是,是否有一种简单的方法可以将 Controller 从默认映射闭包中“排除”?
最佳答案
解决方案是更改默认映射,以排除特殊的 Controller URL。
class UrlMappings {
static myExcludes = ["foo"]
static mappings = {
"/foobar/foo/$action"(controller: "foo") // your special Mapping
// the rewritten default mapping rule
"/$aController/$aAction?/$id?"{
controller = { (params.aController in UrlMappings.myExcludes) ? "error" : params.aController }
action = { (params.aController in UrlMappings.myExcludes) ? "notFound" : params.aAction }
constraints {
// apply constraints here
}
}
}
}
对于重写后的默认规则,必须防止使用默认变量名$ controller和$ action。除了error / notFound之外,您还可以重定向到其他位置。
关于grails - 如何嵌套Grails Controller 路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20496112/