Grails - 使用JSON启动域类 [英] Grails - Initiating domain class using JSON
本文介绍了Grails - 使用JSON启动域类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
class Settings {
static constraints = {
uid (可空:假,唯一:真)
person()
}
字符串uid
映射人
}
$ c
以及使用json请求更新数据的Web UI:
{uid:1234,person:{first_name:jhon,last_name:doe}}
在控制器代码中:
def json = request.JSON;
def s = new设置(json);
似乎 s.uid 正在设置,但 s.person 地图保持空白。
我缺少什么?
解决方案您可以在控制器中执行以下操作:
def json = request.JSON;
def s = new设置(json);
s.person = json.person;
这很丑陋,但数据绑定似乎无法处理嵌套的json
I have this simple domain class:
class Settings {
static constraints = {
uid(nullable: false, unique: true)
person()
}
String uid
Map person
}
and a web UI that update the data using a json request:
{"uid":1234 , person:{"first_name" : "jhon" , "last_name" : "doe"}}
in the controller code:
def json = request.JSON;
def s = new Settings(json);
it seems that s.uid is being set however the s.person Map remains empty.
What am I missing?
解决方案 You can do something like the following in your controller:
def json = request.JSON;
def s = new Settings(json);
s.person = json.person;
it's ugly, but the data binding doesn't seem to handle nested json
这篇关于Grails - 使用JSON启动域类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文