[英]Making a Grails domain class with JS Objects inside?
I'm wondering how I would create a Grails domain class with JavaScript objects as variables on the inside of the class. 我想知道如何创建一个Grails域类,并在类内部使用JavaScript对象作为变量。
For example, I am sending a JSON object that looks like this: 例如,我发送的JSON对象如下所示:
{
"name":"task",
"type":{
"label":"Work",
"id":1
},
"priority":{
"label":"Mid Priority",
"id":2
},
"completed":false,
"comments":"",
"creator":"user",
"assignedTo":"user"
}
As you can see, "type" and "priority" are objects in their own. 如您所见,“类型”和“优先级”本身就是对象。 My grails domain class looks like this currently: 我的grails域类当前如下所示:
package server
class Item {
//String username
String name
String type
String priority
boolean completed = false
String comments
String creator
String assignedTo
static constraints = {
name nullable: false
priority nullable: true
type nullable: true
comments nullable: true
creator nullable: false
assignedTo nullable: false
}
}
Obviously the string is incorrect, but I don't know what it should be? 显然该字符串不正确,但是我不知道它应该是什么? Right now everything is saved as it should be in the JSON list except for the type and priority. 现在,除了类型和优先级之外,所有内容均应保存在JSON列表中。
For the SQL DBs no other alternatives other than saving the JSON as a string exist. 对于SQL DB,除了将JSON保存为字符串外,没有其他选择。 All solutions have marshalling/unmarshalling at some stage, but the data is still stored as a TEXT
or BLOB
in a table. 所有解决方案在某个阶段都具有编组/解组功能,但是数据仍以TEXT
或BLOB
形式存储在表中。
NoSQL DB-s like mongo do allow you to store the BSON object as it is. 像mongo这样的NoSQL DB-确实允许您按原样存储BSON对象。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.