Grails UrlMapping重定向以保持DRY

Phi*_*enn 8 grails grails-2.0

我正在使用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 {
                // apply constraints here
            }
        }

        "/"(view:"/index")
        "500"(view:'/error')
    }
}
Run Code Online (Sandbox Code Playgroud)

RedirectController.groovy

class RedirectController {

    def index() {
        redirect(url: params.destination, permanent: true)
    }
}
Run Code Online (Sandbox Code Playgroud)

Tom*_*etz 4

可以实现这一点:

"/$controller/$action?/$id?" (
    controller: 'myRedirectControlller', action: 'myRedirectAction', params:[ controller: $controller, action: $action, id: $id ]
)

"/user/list" ( controller:'user', action:'list' )
Run Code Online (Sandbox Code Playgroud)

在操作中,您将获得 params 中的正常值:

log.trace 'myRedirectController.myRedirectAction: ' + params.controller + ', ' + params.action + ', ' + params.id
Run Code Online (Sandbox Code Playgroud)