我正在使用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')
}
}
Run Code Online (Sandbox Code Playgroud)
我已经在http://grails.org/doc/latest/guide/theWebLayer.html#restfulMappings上阅读了Grails 2.3的最新文档,
但我认为目前尚不清楚.我试过它按照文档但没有结果.并且没有任何关于使用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("Populating parsed json to params")
params << request.JSON
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3338 次 |
| 最近记录: |