我正在使用 Grails 和 RESTful 来开发我的 Web 应用程序。一切正常,直到我将应用程序升级到 Grails 2.3。这是我的 UrlMappings:
我仍然正常发送请求、提交或做一些其他事情,但在 POST、PUT 请求中,参数丢失。服务器只识别我直接放在 URL 上的参数,但提交时在表单或模型中包含的其余参数在“params”变量中找不到。他是我的UrlMappings:
class UrlMappings {
static mappings = {
"/$controller/$action?/$id?"{ constraints {} }
name apiSingle: "/api/$controller/$id"(parseRequest:true){
action = [GET: "show", PUT: "update", DELETE: "delete"]
constraints { id(matches:/\d+/) }
}
name apiCollection: "/api/$controller"(parseRequest:true){
action = [GET: "list", POST: "save"]
}
name api2: "/api/$controller/$action"(parseRequest:true)
name api3: "/api/$controller/$action/$id"(parseRequest:true)
"/"(view:"/welcome")
"500"(view:'/error')
}
}
我已经阅读了 Grails 2.3 的最新文档,位于http://grails.org/doc/latest/guide/theWebLayer.html#restfulMappings http://grails.org/doc/latest/guide/theWebLayer.html#restfulMappings
但我认为还不清楚。我已经尝试按照文档进行操作,但没有结果。并且没有任何关于使用 Grails 2.3 和 RESTful 的示例供我参考。
如何才能让它像以前一样正常工作,并且可以访问REST请求中的所有参数值?太感谢了!
根据这个http://grails.1312388.n4.nabble.com/Grails-2-3-and-parsing-json-td4649119.html http://grails.1312388.n4.nabble.com/Grails-2-3-and-parsing-json-td4649119.html parseRequest
自 Grails 2.3 起没有任何影响
如果您使用 JSON 作为请求正文,您可以访问请求参数:request.JSON.paramName
作为解决方法,您可以添加一个过滤器,将数据从 JSON 填充到参数:
class ParseRequestFilters {
def filters = {
remoteCalls(uri: "/remote/**") {
before = {
if (request.JSON) {
log.debug("Populating parsed json to params")
params << request.JSON
}
}
}
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)