Grails - 使用 JSON 启动域类 [英] Grails - Initiating domain class using JSON

查看:26
本文介绍了Grails - 使用 JSON 启动域类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个简单的域类:

class Settings {
static constraints = {
    uid(nullable: false, unique: true)
    person()
}

String uid
Map person
}

以及使用 json 请求更新数据的 Web UI:

and a web UI that update the data using a json request:

{"uid":1234 , person:{"first_name" : "jhon" , "last_name" : "doe"}}

在控制器代码中:

def json = request.JSON;
def s = new Settings(json);

似乎正在设置 s.uid 但是 s.person 地图仍然是空的.我错过了什么?

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;

很丑,但是数据绑定似乎不能处理嵌套的json

it's ugly, but the data binding doesn't seem to handle nested json

这篇关于Grails - 使用 JSON 启动域类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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