Grails UrlMappings用于未知数量的变量

Jon*_*ram 5 grails url-mapping

我正在使用url映射将URL目录结构转换为站点内的类别,目前使用:

class UrlMappings {

    static excludes = ['/css/*','/images/*', '/js/*', '/favicon.ico']
    static mappings = {       

        "/$category1?/$category2?/$category3?/"(controller: 'category')

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

目前,这支持三个层次的深层次.我希望能够在N> = 1的情况下支持N级深度.

怎么能实现这一目标?

Jon*_*ram 6

星号(单或双)用于wilcard URL映射.

单个星号将匹配给定级别的任何内容:

static mappings = {
    "/images/*.jpg"(controller:"image")
}

// Matches /images/logo.jpg, images/header.jpg and so on
Run Code Online (Sandbox Code Playgroud)

双星号将匹配多个级别上的任何内容:

static mappings = {
    "/images/**.jpg"(controller:"image")
}

// Matches /images/logo.jpg, /images/other/item.jpg and so on
Run Code Online (Sandbox Code Playgroud)

结合?for可选的映射匹配,以下内容将在问题的上下文中起作用:

class UrlMappings {

    static excludes = ['/css/*','/images/*', '/js/*', '/favicon.ico', '/WEB-INF/*']
    static mappings = {
        "/**?"(controller: 'category')

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