【问题标题】:Grails: how to set a parameter for the whole group in UrlMappingsGrails:如何在 UrlMappings 中为整个组设置参数
【发布时间】:2017-03-31 07:09:38
【问题描述】:

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

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

group ("/v2") {

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

   "/folders"(resources: 'folder')

   apiVersion = 2
}

问题是参数apiVersion 没有在控制器操作中的params 中定义。

如果在每个资源中都像这样定义该参数,则该参数已正确设置:

group ("/v2") {

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

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

}

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

【问题讨论】:

    标签: rest grails url-mapping grails-2.5 urlmappings.groovy


    【解决方案1】:

    解决方法将使用命名空间...虽然我尝试在组级别定义它不会奏效,但您可以尝试一下。但在资源级别定义甚至适用于嵌套资源。

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2010-10-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-06-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多