grails - Grails-包中所有 Controller 的URL重写

标签 grails url-rewriting

我想知道是否有可能重写特定程序包中所有 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/

相关文章:

grails - 如何使用Grails可搜索(lucene)以最有效的方式执行等效的Criteria查询

mongodb - 使用 grails gorm 在 mongodb 中使用 findAndModify

Grails:将插件类导入到 _Events.groovy

apache - 将 {query}.ts 重写为 ts.php?{query}

testing - nginx 将 rewrite_log 存储在哪里?

maven - Grails和GGTS在哪里存储Maven依赖项?

rest - 消费网络服务

.htaccess - htaccess - 重定向所有 PDF 文件(不包括指定文件夹中的 PDF)

.htaccess - 索引文件动态子域冲突的htaccess规则

Azure API 管理 "rewrite url"- 如何删除 URL 前缀