【问题标题】:Grails URLMapping deep pathGrails URLMapping 深层路径
【发布时间】:2012-02-14 20:56:18
【问题描述】:

我有一个类似的网址:

/test/abs/rdc/tx.js

我需要能够为我的控制器获取 /abs/rdc/tx.js 部分。

我试过(在 URLMapping 中):

/test/$target**

它会返回除 .js 之外的所有内容

我有

grails.mime.file.extensions = true 

有什么想法吗?

UrlMapping and file name extension 不起作用,因为它总是返回 .html

【问题讨论】:

    标签: grails url-mapping


    【解决方案1】:

    Grails 2.0 对解析格式的方式进行了一些更改。使用您提供的链接中的示例,只需更新代码以使用response.format

    def path = params.path
    if (!FilenameUtils.getExtension(path) && response.format) {
      path += ".${response.format}"
    }
    

    更多信息在Content Negotiation 下的手册中。向下滚动到标题为请求格式与响应格式的部分。

    【讨论】:

    • 这就是我提供的“UrlMapping 和文件扩展名”链接所说的。 .${response.format} 总是返回“html”,这是不正确的。我会检查内容协商链接。谢谢
    • 不,请阅读我的回复。 request.format 总是返回 html,response.format 返回正确的扩展名。试试看——我做到了。
    【解决方案2】:

    你可以试试这个:

    //Grails 2.3.x
    "/$controller/$action?/$id?(.${format})?"{
        constraints {
            // apply constraints here
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-01-23
      • 2014-10-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-10-10
      • 2019-10-07
      相关资源
      最近更新 更多