【发布时间】:2015-07-02 17:51:42
【问题描述】:
我在我的 Grails 2.3.5 应用程序中设置了一个 Restful 控制器。通过 PUT 将对象发送到我的端点时,该对象不会得到更新。我的 println 没有显示更新的数据,而是显示原始数据。我不明白为什么。
Restful 控制器:
import grails.rest.RestfulController
class PluginSettingController extends RestfulController {
static responseFormats = ['json', 'xml']
PluginSettingController() {
super(PluginSetting)
}
@Override
def update(PluginSetting setting){
println(setting.name)
// This prints out the old name: "Old name"
}
域类:
class PluginSetting {
String name
String value
static constraints = {
name(nullable:false, blank:false, unique: true)
value(nullable:false, blank:false)
}
}
卷曲请求:
curl -i -X PUT -d "{'name':'NEW','value':'my value', 'id':1}" http://localhost:8080/app/pluginSettings/1
旧对象(这是我在向 URL 'http://localhost:8080/app/pluginSettings/1' 发送 GET 时得到的)
{
"class": "configuration.PluginSetting",
"id": 1,
"name": "Old name",
"value": "my value"
}
【问题讨论】:
-
网址映射? debug 告诉你什么参数值在 update() 中?
-
调试告诉我什么。但我发现了错误。缺少内容类型:-H "Content-Type: application/json"
标签: rest grails controller