Best way to create an Admin section in Grails

二次信任 提交于 2019-11-29 18:52:40

问题


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!


回答1:


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.




回答2:


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.




回答3:


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.



来源:https://stackoverflow.com/questions/1133464/best-way-to-create-an-admin-section-in-grails

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!