gpt4 book ai didi

Grails GORM : How to do reflexion on embedded domains?

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

我想对域关联进行反射(reflection),以自动为 RESTful WS(脚手架)生成 JSON/XML 格式的类描述 rune 件。
示例域是:

class Roof {
Chimney chimney = new Chimney()
static embedded = ['chimney']
}

class Chimney {
float height
}
我正在使用此代码来了解 GORM 类类型:
GrailsDomainClassPersistentEntity entity = Roof.gormPersistentEntity

entity?.persistentProperties.each { PersistentProperty property ->
Class<?> cl = property.getType()
}
当属性是关联时,cl 变量获取关联域的类。当关联是标准的 hasOne 或 hasMany 时,这非常有效。我发现的问题是,当嵌入属性时,类的类型导致 org.codehaus.groovy.grails.commons.DefaultGrailsDomainClassProperty。
我不知道另一种方法来发现该嵌入属性的类。任何可能性(嵌入式静态属性......等)?
编辑:
Embedded e = property
e.getAssociatedEntity() //null

最佳答案

检查 embedded 的值域类的字段并扫描类属性的名称以查找匹配项

关于Grails GORM : How to do reflexion on embedded domains?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26403411/

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