我在 Grails 中有一个使用createCriteria()
. 如何强制对结果执行排序,然后应用偏移量和最大约束。
代码:
def history = Termin.createCriteria().list([max:10, offset:offset]) {
and{
//some query constraints
}
order('id', 'desc')
}
这可能会做同样的事情:
def history = Termin.createCriteria().list([max:10, offset:offset,order:'desc',sort:'id']) {
and{
//some query constraints
}
}
数据库是 postgreSQL 7.5,构建的查询如下所示:
select
something
from
somewhere
left outer join
something
on something
left outer join
something
on something
left outer join
something
on something
where
(
something
)
order by
this_.th_id desc limit ? offset ?