如何在grails域类中按降序应用索引?

时间:2016-07-25 10:55:55

标签: grails gorm grails-domain-class

我写了一个域类

class ReportCallByUser {
Integer userId;
String userName;
String reportName;
Date timeOfReportCall;

static constraints = {
}

static mapping = {

    timeOfReportCall index: 'time_of_report_call_index'
}

最后一行在数据库中创建索引,但是按升序排列。如何在' timeOfReportCall '上创建索引?降序排列?
提前谢谢。

2 个答案:

答案 0 :(得分:1)

关于索引创建,没有order这样的事情。它是查询指定排序的能力:

ReportCallByUser.list( [ sort:'timeOfReportCall', order:'[desc|asc]' ] )

答案 1 :(得分:0)

我假设您在使用GORM查询数据库时,默认情况下希望结果按降序排列。如果是这种情况,您可以在映射中指定排序顺序。

static mapping = {
    sort timeOfReportCall:"desc"
}

希望有所帮助。