如何为Grails插件定义url范围

如何为Grails插件定义url范围,grails,Grails,我有一个Grails应用程序,它应该由多个自己实现的Grails插件扩展。与其他插件一样,我将它们导入BuildConfig.groovy 可以在根url下调用每个插件的控制器: http://localhost/application/<ctrlPlugin1> http://localhost/application/<ctrlPlugin1>/<endpoint1> http://localhost/application/<ctrlPlugin2

我有一个Grails应用程序,它应该由多个自己实现的Grails插件扩展。与其他插件一样,我将它们导入BuildConfig.groovy

可以在根url下调用每个插件的控制器:

http://localhost/application/<ctrlPlugin1>
http://localhost/application/<ctrlPlugin1>/<endpoint1>
http://localhost/application/<ctrlPlugin2>
http://localhost/application/
http://localhost/application//
http://localhost/application/
此时,plugin1中的控制器名称必须与plugin2中的控制器名称不同

如何定义url范围,以便插件的所有端点都位于特殊的url路径下,并且插件中的控制器名称可以相等

http://localhost/application/<plugin1>/<ctrlPlugin1>
http://localhost/application/<plugin1>/<ctrlPlugin1>/<endpoint1>
http://localhost/application/<plugin2>/<ctrlPlugin2>
http://localhost/application//
http://localhost/application///
http://localhost/application//
您可以通过在相应插件的每个控制器中添加
静态名称空间='ctrlPlugin1'
来实现类似的功能

实现这一点的另一种方法是创建一个
CrtlPluginXUrlMappings.groovy
,将其相应的控制器映射到特定的基本路径下,如下所示:

class CrtlPluginXUrlMappings {
  "/crtlPluginX/customers" resources: "customer"
  "/crtlPluginX/orders" resources: "order"
}