您的位置:首页 > 大数据 > 人工智能

grails 在一对多关系中如何排序多对象

2008-05-15 14:52 155 查看

这是摘自grails官方网站FAQ里的一个问题

翻译

问题:在一对多的关系中,如何得到一个有序的多对象

在Author和Book例子中,Book 域类(domain class)必须实现Comparable接口,然后把 Author域类里的books类型设置为 SortedSet

源代码同原文

原文:

Q: In a one-to-many relationship, how to do I have a sorted set of the many objects?

In the Author/Book example, Book must implement the Comparable interface, and the set of books must be of type SortedSet:

class Author {

Long id    Long version

def relatesToMany = [ books : Book ]

String name    SortedSet books

}

原文地址:http://grails.codehaus.org/FAQ
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息