在 Grails 中创建管理部分的最佳方法

发布于 2024-07-29 01:00:18 字数 286 浏览 3 评论 0原文

嘿,

我想知道在 Grails 应用程序中创建管理(后端)部分的最佳方法是什么?

我想在 Grails 的“controllers”文件夹中创建一个“Admin”文件夹来放置我所有的管理控制器。 但是我是否必须为每个管理控制器手动创建 URL 映射?

我已经使用 generate-all 命令生成了所有前端 GSP,该命令采用域类,但知道如何为我的管理部分生成 CRUD(具有相同的域)班级)。 我完蛋了吗?

非常感谢您的提示!

Hy,

I'm wondering what's the best way to create an Admin (backend) section in a Grails app ?

I want to create an "Admin" folder in the "controllers" folder of Grails to put all my admin controllers. But then will I have to create manually the URL mapping for each Admin controller?

I have already generated all my frontend GSP with the genernate-all command which takes a Domain Class but know how can I generate my CRUD for my admin section (with the same domain class). Am I screwed ?

Thanks a lot for your tips!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

别把无礼当个性 2024-08-05 01:00:18

我对此的偏好是有一个单独的管理员应用程序。 将所有域类放入一个插件中,并将该插件安装到管理应用程序和消费者应用程序中。

这样,您就可以根据自己的喜好调整控制器,而不必担心最终用户会碰到它们。 共享服务也可以在域插件中。

您可以将一个名为 BuildConfig.groovy 的特殊文件放入 grails-app/conf 中,您可以在其中指定“本地”插件,例如自动引入类路径的域插件,而无需打包/安装插件。 让它变得超级简单。

My preference for this is to have a separate application for admin. Stick all of your domain classes in a plugin and install that plugin into both the admin application and the consumer appilcation.

That way, you can tweak the controllers to your hearts content and not worry about end users hitting them. Shared services can also be in the domain plugin.

There's a special file that you can put in your grails-app/conf called BuildConfig.groovy where you can specify "local" plugins like the domain plugin that are automatically brought into the classpath without having to package/install the plugin. Makes it super easy.

Hello爱情风 2024-08-05 01:00:18

您可以像任何其他控制器一样创建管理控制器,并使用过滤器来确保仅使用以下方式登录的用户管理员权限可以访问它们。

You could create your admin controllers like any other controller and use a filter to make sure only logged in users with admin privilages can access them.

神也荒唐 2024-08-05 01:00:18

很晚了,但这里有一种可能有用的方法,至少对于较小的应用程序(我使用的是 Grails 2.0):

在 conf/UrlMappings.groovy 中:

class UrlMappings {
  static mappings = {
    "/admin/$controller/$action?/$id?"{ constraints { // apply constraints here
      } }
    '/admin' (controller: 'yourMainController', action: 'list')
    '/' (controller: 'public', action:'index')
    // For the PublicController to handle *all* other requests (like /foo/bar/):
    // '/**' (controller: 'public', action:'index')
    "500"(view:'/error')
  }
}

注意 如您所见,我没有以任何方式保证这一点。

Very late to this, but here is one way that might be useful, at least for a smaller application (I'm using Grails 2.0):

In conf/UrlMappings.groovy:

class UrlMappings {
  static mappings = {
    "/admin/$controller/$action?/$id?"{ constraints { // apply constraints here
      } }
    '/admin' (controller: 'yourMainController', action: 'list')
    '/' (controller: 'public', action:'index')
    // For the PublicController to handle *all* other requests (like /foo/bar/):
    // '/**' (controller: 'public', action:'index')
    "500"(view:'/error')
  }
}

Note As you can see, this i not secured in any way.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文