当升级到Grails 2.3.0时,使用RESTful请求缺少参数 [英] Missing parameters with RESTful request when upgrading to Grails 2.3.0
问题描述
我仍然正常发送请求,提交或做一些其他的事情,但在POST,PUT请求中,参数丢失。服务器只是直接识别我直接放在URL上的参数,但是在params变量中找不到提交时仍然保留在表单或模型中。他是我的UrlMappings:
class UrlMappings {
static mappings = {
$控制器/ $动作?/ $ id?{constraints {}}
名称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 / $ (parseRequest:true)
$ b/ / welcome)
500(查看:'/ error')
}
}
我已经阅读了Grails 2.3的最新文档,在 http:// grails .ORG / DOC /最新/引导/ theWebLayer.html#restfulMappin gs
但我认为不清楚。我试过它遵循文档,但没有结果。并且没有任何关于使用Grails 2.3与RESTful的示例来引用。
如何使之正常工作,并且可以访问REST请求中的所有参数值?非常感谢你!
根据这个 http://grails.1312388.n4.nabble.com/Grails-2-3-and-parsing-json- td4649119.html parseRequest
自Grails 2.3以来没有任何效果
如果您将JSON用作请求体,可以将请求参数作为 request.JSON.paramName
作为解决方法,您可以添加一个将填充数据的过滤器从JSON到params:
class ParseRequestFilters {
def filters = {
remoteCalls uri:/ remote / **){
before = {
if(request.JSON){
log.debug(填充解析json到params)
params << request.JSON
}
}
}
}
}
I am using Grails with RESTful to develop my web application. Everything works fine, till I upgrade my application to Grails 2.3. Here is my UrlMappings: I still send request, submit or do some other things normally, but in POST, PUT requests, the parameters are missing. Server just recognize only the parameters I put on the URL directly, but the remain I enclose in form or model when submit cannot be found in the "params" variable. He is my 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')
}
}
I have read the latest document of Grails 2.3, at http://grails.org/doc/latest/guide/theWebLayer.html#restfulMappings
but I think it is not clear. I have tried it follow the documentation but have no result. And there are no any sample about using Grails 2.3 with RESTful for me to refer.
How can I make it work normally as before, and can access all parameter values in REST request? Thank you so much!
According to this http://grails.1312388.n4.nabble.com/Grails-2-3-and-parsing-json-td4649119.html parseRequest
has no effect since Grails 2.3
If you use JSON as request body you can accees request params as request.JSON.paramName
As a workaround you can add a filter that will populate data from JSON to params:
class ParseRequestFilters {
def filters = {
remoteCalls(uri: "/remote/**") {
before = {
if (request.JSON) {
log.debug("Populating parsed json to params")
params << request.JSON
}
}
}
}
}
这篇关于当升级到Grails 2.3.0时,使用RESTful请求缺少参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!