gpt4 book ai didi

grails - Grails GORM:常规 map

转载 作者:行者123 更新时间:2023-12-02 14:13:59 25 4
gpt4 key购买 nike

具有以下域类:

class Word {
Map translations
static hasMany = [translations: String]

String toString(){
id
}
}

还有一些保存在grails bootstrap 中的实例:
def word1 = new Word(translations: [en:"game"]);
word1.save(failOnError: true, flush: true)

def word3 = new Word(translations: [en:"gate"]);
word3.save(failOnError: true, flush: true)

def word2 = new Word(translations: [en:"life"]);
word2.save(failOnError: true, flush: true)

无法正确获取 translations字段。例如:
//input
println Word.findAll().each {
println it.translations
}
//output
[:]
[:]
[:]
[1, 2, 3]

怎么了?

最佳答案

医生说:

如果您想要一个简单的字符串/值对映射,GORM可以使用以下内容进行映射:

class Author {
Map books // map of ISBN:book names
}
def a = new Author()
a.books = ["1590597583":"Grails Book"]
a.save()

关于grails - Grails GORM:常规 map ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9113769/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com