我有一个域名类(class)
class UserProfile {
List<String> interests = [];
ObjectId id;
String username;
String password;
String email;
static constraints = {
}
}
由gorm正确地保留在mongodb中
def user = new UserProfile(username:"name",password:"pass",email:"asd@asd.com",interests: ['women','dogfight']);
user.save()
可以在mongo控制台中验证:
{“_id”:ObjectId(“528fd78003646357efb421c0”),“电子邮件”:“asd@asd.com”,“兴趣”:[“妇女”,“打架”],“密码”:“通过”,“用户名”: “名称”,“版本”:0}
所以我得到这个对象
Controller 中的
UserProfile.find() as JSON
并得到{“class”:“domain.users.UserProfile”,“id”:{“class”:“org.bson.types.ObjectId”,“inc”:-273407552,“machine”:56910679,“new”:false ,“时间”:1385158528000,“时间第二”:1385158528},“电子邮件”:“asd \ u0040asd.com”,“密码”:“通过”,“用户名”:“名称”}
如您所见,很遗憾,兴趣列表没有显示
我将不胜感激任何帮助。谢谢
附言Grails v2.3.3
最佳答案
在域类中指定关联应该会有所帮助。
static hasMany = [interests: String]
关于json - 字符串列表未呈现为JSON,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20155636/