2012-02-14 52 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 
    } 
}