Grails2.3.8检查url映射是否出现字符串

Grails2.3.8检查url映射是否出现字符串,grails,grails-2.0,url-mapping,Grails,Grails 2.0,Url Mapping,我正在尝试映射以下内容 //localhost:8080/user/login/&debug=1 //localhost:8080/user/&debug=1 如果出现字符串“&debug=1”,则执行某些控制器的操作。您可以使用如下URL映射 "/**&debug=1"(controller:"defaultDebug"){ action = [GET: "show"] } 通过使用双通配符,您可以捕获以&debug=1结尾的任何内容,您可以在需要时使用来执行重定向 cla

我正在尝试映射以下内容

//localhost:8080/user/login/&debug=1

//localhost:8080/user/&debug=1


如果出现字符串“&debug=1”,则执行某些控制器的操作。

您可以使用如下URL映射

"/**&debug=1"(controller:"defaultDebug"){
    action = [GET: "show"]
}
通过使用双通配符,您可以捕获以
&debug=1

结尾的任何内容,您可以在需要时使用来执行重定向

class DebugFilters {
    def filters = {
        debugCheck(controller: '*', action: '*') {
            before = {
                if (params.debug == '1') {
                    redirect(controller: 'some', action: 'debug')
                    return false
                }
            }
        }
    }
}
如果您只想在特定url映射的控制器和操作之间切换,则还可以使用如下url映射,而不是完全使用过滤器:

//UrlMappings.groovy
"/user/login" {
    controller = { params.debug == '1' ? 'some' : 'user' }
    action     = { params.debug == '1' ? 'debug': 'index' }

    // Note the use of a closure in ternary operations
    // params is available in a closure (delegated) 
    // because it is not available in by default
}

你试过什么吗?