我正在使用Grails 2.1.1并希望添加一些映射到Controller Actions的自定义URL.
我可以这样做,但原始的映射仍然有效.
例如,我add-property-to-directory在my中创建了一个映射,UrlMappings如下所示:
class UrlMappings {
static mappings = {
"/add-property-to-directory"(controller: "property", action: "create")
"/$controller/$action?/$id?"{
constraints {
// apply constraints here
}
}
"/"(view:"/index")
"500"(view:'/error')
}
}
Run Code Online (Sandbox Code Playgroud)
现在,正如我所料,我可以击中/mysite/add-property-to-directory并执行它PropertyController.create.
但是,我仍然可以击中/mysite/property/create它,它将执行相同的PropertyController.create方法.
在干燥的精神,我想从做301重定向/mysite/property/create到/mysite/add-property-to-directory.
我找不到办法做到这一点UrlMappings.groovy.有谁知道我可以在Grails中实现这一目标的方式?
非常感谢你!
UPDATE
根据Tom的回答,这是我实施的解决方案:
UrlMappings.groovy
class UrlMappings {
static mappings = {
"/add-property-to-directory"(controller: "property", action: "create")
"/property/create" {
controller = "redirect"
destination = "/add-property-to-directory"
}
"/$controller/$action?/$id?"{
constraints { …Run Code Online (Sandbox Code Playgroud)