从Grails控制器,我想重定向到这个(使用查询字符串):
/mycontroller/myaction?id=3
我写了这段代码:
def a = 3;
redirect (controller:"mycontroller",action:"myaction",params:[id:a])该代码将产生:
/肌控制器/肌动作/3
我知道id是一个特殊的参数。它将是url而不是查询字符串。我尝试另一个参数
def name = "John";
redirect (controller:"mycontroller",action:"myaction",params:[name:name])will生产:
/mycontroller/myaction?name=John
发布于 2015-05-27 06:48:24
所描述的行为是UrlMappings配置的结果。如果使用默认映射,则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。
https://stackoverflow.com/questions/30472811
复制相似问题