我将UrlMappings中的某些URL从默认更改为新的。默认返回格式为JSON,并且xxx?format=xml
仍可以检索XML响应。但是,URI扩展方法停止了工作(xxx.json或xxx.xml),这是我仍然希望拥有的东西。有什么办法可以将其重新添加到位?
原始文件(可以使用URI扩展名):
"/api/companies"(resources:"company") {
"/infos"(resources:"companyInfo")
}
到(URI扩展名不起作用):
"/api/companies"(resources:"company") {
"/info"(controller:"companyInfo", action: 'show', method: 'GET')
"/info"(controller:"companyInfo", action: 'save', method: 'POST')
"/info"(controller:"companyInfo", action: 'update', method: 'PUT')
"/info"(controller:"companyInfo", action: 'delete', method: 'DELETE')
}
最佳答案
您需要将格式捕获(使用(.$format)?
)添加到URI:
"/api/companies"(resources:"company") {
"/info(.$format)?"(controller:"companyInfo", action: 'show', method: 'GET')
"/info(.$format)?"(controller:"companyInfo", action: 'save', method: 'POST')
"/info(.$format)?"(controller:"companyInfo", action: 'update', method: 'PUT')
"/info(.$format)?"(controller:"companyInfo", action: 'delete', method: 'DELETE')
}
关于grails - 自定义URL上具有URI扩展的内容协商,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23728524/