将控制器分组到Grails中的功能包(Group Controllers to functional Packages in Grails)

系统教程 行业动态 更新时间:2024-06-14 17:04:03
将控制器分组到Grails中的功能包(Group Controllers to functional Packages in Grails)

我正在开发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).

更多推荐

本文发布于:2023-04-24 21:15:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/dzcp/1d8816f089752b34bdecf768b6602de0.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:控制器   功能   Grails   Group   functional

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!