2015-03-19 76 views
2

在我的GORM对象中,我使用了@ToString注释。例如,GORM对象的打印ID

@ToString(includeNames=true, includePackage=false) 
class BasketSet { 
    ... 

我不明确,因为我使用格姆默认ID为格姆对象添加一个ID字段,我的问题是,id没有在印刷的toString()。有任何想法吗?

+0

那么为什么不执行字符串的ToString(){} this.id我 – dsharew 2015-03-19 13:59:37

+0

要整齐/ Grails的/ Groovy的方式为所有对象格姆为什么 – 2015-03-19 14:23:58

回答

1

总是有创建自己的toString

class BasketSet{ 
    String toString(){ 
      return "${this.id}" 
     } 
} 
+0

不是posibility只有'this.id'代替'“$ {this.id}”'? – Abs 2015-03-19 17:11:13

+0

对不起,没有特别的原因。 这只是因为我习惯了它。 如果您确实想要返回更复杂的消息,如 “BasketSet的标识为2”,则使用$ {this.id}。 return“BasketSet的ID是$ {this.id}”, 所以我不需要连接字符串。 但无论哪种方式都很好。 – msjonatan 2015-03-19 18:07:44