我想知道是否有可能重写特定程序包中所有 Controller 的URL。我需要将“admin”包中所有 Controller 的URL更改为“/ admin / $ controller”而不是“/ $ controller”,以便可以通过Spring Security保护它。非常感谢。
问候,
洛扎
最佳答案
因此,今天我根据this article实现了该解决方案:
// AppCtx - check the article above
for (controller in AppCtx.grailsApplication.controllerClasses) {
def cName = controller.logicalPropertyName
def packageName = controller.packageName
if (packageName.contains(".admin") || packageName.contains(".springsecurity")) {
"/admin/${cName}/$action?/$id?"(controller: cName) {
constraints {
}
}
} else {
"/${cName}/$action?/$id?"(controller: cName) {
constraints {
// apply constraints here
}
}
}
}
关于grails - Grails-包中所有 Controller 的URL重写,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10129501/