我们的Grails 2.5网络应用程序具有REST API。

我们需要启动API的新版本,以便使用UrlMappings.groovy创建一个组,如下所示:

group ("/v2") {

   "/documents"(resources: 'document') {
     "/meta"(resource: 'documentInfo', includes: ['show', 'update'])
   }

   "/folders"(resources: 'folder')

   apiVersion = 2
}

问题是在 Controller Action 中的apiVersion中未定义参数params

如果在每个资源中都定义了该参数,则该参数应如下设置:
group ("/v2") {

   "/documents"(resources: 'document') {
     "/meta"(resource: 'documentInfo', includes: ['show', 'update']) {
       apiVersion = 2
     }
     apiVersion = 2
   }

   "/folders"(resources: 'folder') {
     apiVersion = 2
   }

}

如何在组级别上正确定义参数?

最佳答案

解决方法将使用 namespace ...尽管我在组级别定义它的尝试无法成功,但是您可以尝试一下。但是,即使对于嵌套资源,在资源级别进行定义也可以。

group ("/v2") {

   "/documents"(resources: 'document', namespace:'v2') {
     "/meta"(resource: 'documentInfo', includes: ['show', 'update'])
   }

   "/folders"(resources: 'folder', , namespace:'v2')
}

10-07 19:52
查看更多