(Quick Reference)

6.4.6 Mapping Wildcards - Reference Documentation

Authors: Graeme Rocher, Peter Ledbrook, Marc Palmer, Jeff Brown, Luke Daley, Burt Beckwith

Version: null

6.4.6 Mapping Wildcards

Grails' URL mappings mechanism also supports wildcard mappings. For example consider the following mapping:
El mecanismo de mapeo de URL de Grails tambien soporta el mapeo de wildcards. Por ejemplo considere el siguiente mapeo:

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

This mapping will match all paths to images such as /image/logo.jpg. Of course you can achieve the same effect with a variable:
Este mapeo empatara todas las rutas de imagenes tales como /image/logo.jpg. Por supuesto puede obtener el mismo efecto con la variable:

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

However, you can also use double wildcards to match more than one level below:
Sin embargo, puede tambien usar dobles wildcards para empatar mas de un solo nivel abajo:

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

In this cases the mapping will match /image/logo.jpg as well as /image/other/logo.jpg. Even better you can use a double wildcard variable:
En este caso el mapeo empatara /image/logo.jpg asi como /image/other/logo.jpg. Aun mejor puede usar la variable de doble wildcard:

static mappings = {
    // will match /image/logo.jpg and /image/other/logo.jpg
    "/images/$name**.jpg"(controller: "image")
}

In this case it will store the path matched by the wildcard inside a name parameter obtainable from the params object:
En este caso sera almacenada la ruta que empate con el wildcard dentro del parametro name obtenible desde el objeto params:

def name = params.name
println name // prints "logo" or "other/logo"

If you use wildcard URL mappings then you may want to exclude certain URIs from Grails' URL mapping process. To do this you can provide an excludes setting inside the UrlMappings.groovy class:
Si usa el wildcard del mapeo de URL entonces querra excluir ciertas URIs del proceso de mapeo de URL de Grails. Para hacer esto puede proveer una setting excludes dentro de la clase UrlMappings.groovy:

class UrlMappings {
    static excludes = ["/images/*", "/css/*"]
    static mappings = {
        …
    }
}

In this case Grails won't attempt to match any URIs that start with /images or /css.
En este caso Grails no intentara de empatar ninguna URI que comience con /images o /css.