我有两个域类
1的 CustomerInterest.groovy
static hasMany = [activities:Activity]
static belongsTo=[customer:Customer,projectProperty:ProjectProperty]
static mapping={
activities sort:'dateCreated',order:'desc'
}
2的 Activity.groovy
Date dateCreated
static belongsTo = [customerInterest:CustomerInterest, employee:Employee]
在控制器中,我这样做..
def customerDetails(Customer customer)
{
def customerInterest=customer.customerInterests
render view:"customerDetails",model:[customerInterest:customerInterest]
}
customerDetails.gsp
<g:each in="${customerInterest}" var="ci">
${ci}
</g:each>
**
问题:我想在活动域的属性 dateCreated 上对 CustomerInterest 进行排序。
**
我们将尽快给予任何帮助。
答案 0 :(得分:1)
试试这个
def customerInterest=customer.customerInterests.sort { it.activities.dateCreated }
答案 1 :(得分:0)
您可以使用旧的Java Comparable
- interface:
class Foo implements Comparable {
int compareTo(anotherObject) {
// complex logic returning -1 or 0 or 1
}
}
然后你可以调用listOfFoos.sort()
并在compareTo方法的帮助下对其进行排序。
请注意(等于)==
也将使用此方法,因此请确保(仅)相同的对象将返回0.