2012-02-14 60 views

回答

3

的Grails 2.0已经做了一些修改的格式进行解析的方式。使用从您提供的链接的例子,刚刚更新的代码使用response.format

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

更多信息是Content Negotiation下的说明书中无。向下滚动至标题为的部分请求格式与响应格式

+0

这正是“urlMapping中和文件扩展名”链接我只要说到做到。 $ {response.format}总是返回“html”,这是不正确的。我将检查内容协商链接。谢谢 – user965697 2012-02-14 21:37:39

+0

不,请阅读我的回复。 'request.format'总是返回html,'response.format'返回正确的扩展名。尝试一下 - 我做到了。 – OverZealous 2012-02-14 21:54:44

+0

Doh!很抱歉。有效!谢谢! – user965697 2012-02-14 22:09:14

1

你可以试试这个:

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