Grails REST with @Resource - PUT没有更新 [英] Grails REST with @Resource - PUT is not updating

查看:83
本文介绍了Grails REST with @Resource - PUT没有更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我现在正在学习grails(2.4.0),并且自动生成REST方法有一个奇怪的问题。所以,我有一个简单的域

p>

  @Resource(uri ='/ unit',formats = ['json'])
class Unit {
字符串名称;
}

我可以使用GET / POST / DELETE方法成功列出/创建/删除实例,但PUT方法什么都不做:

  curl -i -X PUT -HContent-Type:application / json-d '{name:fail,id:65}'localhost:8080 / app / unit / 65 
HTTP / 1.1 200 OK
服务器:Apache-Coyote / 1.1
位置:http:// localhost:8080 / app / unit / 65
内容类型:application / json; charset = UTF-8
传输编码:分块
日期:Sun,01 Jun 2014 09:25:02 GMT

{class:app.Unit,id:65,name:test}

后续的GET请求也会返回name:test而不是name:fail



我可以做错了吗?

解决方案

这是一个只涉及更新(而不是新创建的实例)的错误。我已经完成了修复,我们将在2.4.1中包含此修复程序。请参阅 https://jira.grails.org/browse/GRAILS-11462 。 p>

缺点是即使请求有一个正文,请求参数也会进行更新。解决方法是更改​​,以便更新完成时,如果请求具有正文,则使用正文,如果不正确,则使用请求参数。



对不起,感谢您的输入。


I'm learning grails (2.4.0) right now and have a weird problem with automatically generated REST methods.

So, i have a simple domain

@Resource(uri = '/unit', formats = ['json'])
class Unit {
    String name;
}

I can successfully list/create/delete instances with GET/POST/DELETE methods, but PUT method does nothing:

curl -i -X PUT -H "Content-Type: application/json" -d '{"name":"fail", "id":65}' localhost:8080/app/unit/65
HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
Location: http://localhost:8080/app/unit/65
Content-Type: application/json;charset=UTF-8
Transfer-Encoding: chunked
Date: Sun, 01 Jun 2014 09:25:02 GMT

{"class":"app.Unit","id":65,"name":"test"}

subsequent GET requests will also return name:test instead of name:fail

What i can be doing wrong?

解决方案

This is a bug which only relates to updates (not to newly created instances). I have worked up the fix and we will have this fix included in 2.4.1. See https://jira.grails.org/browse/GRAILS-11462.

The short of it is that updates are being done with the request parameters, even if the request has a body. The fix is to change that so when the update is done, if the request has a body then the body is used and if it does not, the request a parameters are used.

Sorry for the trouble and thanks for the input.

这篇关于Grails REST with @Resource - PUT没有更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆