Grails 控制器和 URL 映射魔法

Grails Controller and URL Mapping Magic

Grails 3.0.1 这里。我希望完成特定的 URL/controller 结构。我的应用程序部署在根上下文 (/),这意味着它在本地以 http://localhost:8080 运行,在非本地以 http://someserver.example.org.

运行

我希望 /app/* 下的所有内容都经过身份验证并被视为 "core app" 的一部分(需要登录)。 URL 之外的任何内容都被视为 public 网站的一部分(未经身份验证)。但是,我希望 /app/ 本身只是某种占位符;我希望它成为一个 Grails 控制器。因此:

因此 http://localhost:8080/app/order/create 将通过身份验证,如果已登录,将调用 OrderController#create 操作,这可能会呈现 createOrder.gsp.

我想知道 Grails 3.x 方法是什么:

  1. 允许 /app/ 存在,但不能作为控制器(就像我说的,也许只是 redirecting/mapping 登录页面)
  2. 允许 /app/ 下的任何内容遵循 controller/action 范式

关于如何实现这个的想法?


更新

class UrlMappings {
    static mappings = {
        "/$controller/$action?/$id?(.$format)?"{
            constraints {
                // apply constraints here
            }
        }

        "/app/$controller/$action?/$id?" {
            ???
        }

        "/"(view:"/index")
        "500"(view:'/error')
        "404"(view:'/notFound')
    }
}

Grails 可以为控制器声明名称空间。有了这个,您可以将所有控制器放在命名空间 'app' 下,这应该正好是您的第二个问题。有关详细信息,请参阅 docs

然后使用正常的 spring 安全设置(@Secured 例如)完成安全限制。