我正在开发Grails应用程序。 我现在有大约20个控制器,会有更多。 有没有办法在功能包中对控制器进行分组? 我希望有类似的东西:
grails-app/administration/<controller classes> grails-app/usercontent/<controller classes> grails-app/publiccontent/<controller classes>如果Package不会出现在URL中,那将是最好的。
I'm developing a Grails App. I have about 20 Controllers right now and there will be more. Is there a way to Group the Controllers in functional Packages? I would like to have something like:
grails-app/administration/<controller classes> grails-app/usercontent/<controller classes> grails-app/publiccontent/<controller classes>The best would be if the Package would not appear in the URL.
最满意答案
您可以通过将控制器放入Java / Groovy包中来执行类似操作:
package administration class UserController { ... }并将源代码放入grails-app/controllers/相应子目录中,例如。 grails-app/controllers/administration/UserController.groovy 。 这不会更改默认URL映射(即包名称不包含在URL中)。 但请注意,即使在不同的软件包中,您的控制器名称也必须是唯一的!
我不知道有任何简单的方法来实现你建议的目录布局(路径中没有controller/ )。
You can do something similar by putting your controllers into Java/Groovy packages:
package administration class UserController { ... }and placing the source code into corresponding sub-directories of grails-app/controllers/, eg. grails-app/controllers/administration/UserController.groovy. This won't change the default URL Mapping (ie. the package name is not included in the URL). Note however, that your controller names have to be unique even across different packages!
I'm not aware of any easy approach to achieve the directory layout you suggested (no controller/ in the path).
更多推荐
发布评论