参数';id';在Grails重定向中成为查询字符串

参数';id';在Grails重定向中成为查询字符串,grails,url-redirection,Grails,Url Redirection,从Grails控制器,我想重定向到以下位置(使用查询字符串): /mycontroller/myaction?id=3 我写了这段代码: def a = 3; redirect (controller:"mycontroller",action:"myaction",params:[id:a]) 此代码将生成: /mycontroller/myaction/3 我知道id是一个特殊的参数。它将是url而不是查询字符串。我尝试另一个参数 def name = "John"; redirect (

从Grails控制器,我想重定向到以下位置(使用查询字符串):

/mycontroller/myaction?id=3

我写了这段代码:

def a = 3;
redirect (controller:"mycontroller",action:"myaction",params:[id:a])
此代码将生成:

/mycontroller/myaction/3

我知道id是一个特殊的参数。它将是url而不是查询字符串。我尝试另一个参数

def name = "John";
redirect (controller:"mycontroller",action:"myaction",params:[name:name])
将产生:

/mycontroller/myaction?名称=John


您描述的行为是配置的结果。 如果使用默认映射,则
id
参数将被置于所述位置
$id?

class UrlMappings {    
    static mappings = {
        "/$controller/$action?/$id?"{
            constraints {
                // apply constraints here
            }
        }
        "/"(view:"/index")
        "500"(view:'/error')
    }
}
一般来说,这没有问题。您还可以将
id
参数设置为查询字符串:

def myaction() {
    def idFromParams = params.id
}
或者您只需重写
UrlMappings