gpt4 book ai didi

grails - Grails domainClasses获得临时属性

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

GrailsDomainClass类具有两种方法:getPropertiesgetPersistentProperties
我有一个域类(MyDomainClass),其中包括:

static transients = {computeStuff}
float computeStuff(){
def thisCouldChange = 3.1
return thisCouldChange //it actually does things but not of consequence to my question
}

好的,我采用了默认的索引页面并对其进行了修改,以列出 MyDomainClass的所有属性,如下所示:
<g:each var="d" in="${grailsApplication.domainClasses.sort { it.fullName } }">
<h2>${d.fullName}</h2>
<g:each var="f" in="${d.properties.sort { it.fieldName } }">
<br>${f.fieldName }
</g:each>
</g:each>

好。那行得通,但它没有任何 transient 属性。我尝试了d.properties和d.persistantProperties,它们似乎给了我相同的结果。在此先感谢您的帮助!!

我需要称它为getComputeStuff或其他名称吗?

我现在已经更改了我的域类以包含此域,但仍然无法获得 transient computeStuff
static transients = ['computeStuff']
float getComputeStuff(){
def thisCouldChange = 3.1
return thisCouldChange //it actually does things but not of consequence to my question
}

这似乎没有什么区别。

最佳答案

去除静态 transient 脱纤。定义您的方法如下:

def getComputeStuff(){
def thisCouldChange = 3.1
return 3.1 //it actually does things but not of consequence to my question
}

之后,在域类上调用getProperties()的属性列表中应出现一个属性调用“computeStuff”。将返回值定义为 def 非常重要。

关于grails - Grails domainClasses获得临时属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6379775/

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