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 非常重要。


评论关闭
IT序号网

微信公众号号:IT虾米 (左侧二维码扫一扫)欢迎添加!