我在UrlMappings.groovy中将命名空间设置为:
"/usa_az/$controller/$action/$id?(.${format})?"(namespace: 'usa_az')
"/usa_ms/$controller/$action/$id?(.${format})?"(namespace: 'usa_ms')
有没有办法做类似的事情:
class NameSpaceInterceptor {
NameSpaceInterceptor(){
matchAll() //match all controllers
}
//Change the name of the view to find it in state-specific folder in views
boolean after() {
if(*controller.namespace* == 'usa_az' ){
view = "/usa_az/$view"
} else if (*controller.namespace* == 'usa_ms' ){
view = "/usa_ms/$view"
}
true
}
}
如何在此拦截器中找到 Controller 的句柄或更重要的是命名空间?
最佳答案
我实际上是按照以下方式做的:
boolean before() {
if (controllerNamespace == "admin") {
}
}
在我的其中一个拦截器中,因此答案应该是通过controllerNamespace。
关于grails - Grails 3如何从拦截器访问 namespace ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30493659/