Tung
07/11/2024, 5:16 PMUrlMappings.groovy, I have two mappings having the same setting like below.
"/$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?Tung
07/17/2024, 10:53 AM