In my `UrlMappings.groovy`, I have two mappings ha...
# questions
t
In my
UrlMappings.groovy
, I have two mappings having the same setting like below.
Copy code
"/$id(.$revisionId)?" {
            controller = "model"
            action = 'show'
            constraints {
                id(nullable: false, validator: { modelId ->
                    def registryFactory = grailsApplication.mainContext.idGeneratorRegistryFactoryBean
                    def registry = registryFactory.object
                    Pattern modelIdRegexes = registry.getRegexForAllModelIdentifiers()

                    modelIdRegexes.matcher(modelId).matches()
                })
                revisionId(matches: /\d+/)
            }
        }
....
"/api/model/$id(.$revisionId)?" {
            controller = "model"
            action = 'show'
            constraints {
                id(nullable: false, validator: { modelId ->
                    def registryFactory = grailsApplication.mainContext.idGeneratorRegistryFactoryBean
                    def registry = registryFactory.object
                    Pattern modelIdRegexes = registry.getRegexForAllModelIdentifiers()

                    modelIdRegexes.matcher(modelId).matches()
                })
                revisionId(matches: /\d+/)
            }
        }
How can I define the body closure once and reuse it instead of duplicating twice?
Anyone has experienced?