Grails表链接到自己 [英] Grails table that links to itself

查看:111
本文介绍了Grails表链接到自己的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



这篇相关文章提出了一个解决方案,但是我无法完成它的工作: href =https://stackoverflow.com/questions/1787120/grails-domain-class-relationship-to-it-self> Grails领域类本身的关系



有一件事我不明白什么可比较的,并且需要添加一个int compareTo(obj)方法。



将以下内容添加到我的代码中而不实现比较编译,但grails在运行时崩溃:

  // NavMenu父
SortedSet子项
static hasMany = [subItems:NavMenu]
static belongsTo = [parent:NavMenu]
static constraints = {parent(nullable:true)}

在此先感谢

解决方案

当您使用 SortedSet ,内部执行排序算法,但需要排序条件。您需要实现 Comparable 接口,因为这是为内部算法提供排序条件的标准方式。



如果您不需要特定的订单,您可以删除 SortedSet子项行,从而避免执行可比较界面。


I would like to create a grails domain class that links to itself.

This related post suggests a solution but I can't get it to work: Grails domain class relationship to itself

For one thing I don’t understand what comparable does and would need to add a int compareTo(obj) method.

Adding the following to my code without implementing Comparable compiles, but grails crashes at runtime:

//NavMenu parent
SortedSet subItems
static hasMany = [subItems: NavMenu]
static belongsTo = [parent: NavMenu]
static constraints = { parent(nullable:true) }

Thanks in advance

解决方案

When you're using SortedSet, a sort algorithm is internally executed, but it needs a sort criteria. You need to implement the Comparable interface because that is the standard way to provide a sort criteria to the internal algorithm.

If you don't need a specific order, you can delete the SortedSet subItems line and thus avoid implementing the Comparable interface.

这篇关于Grails表链接到自己的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆