我有一個使用HQL的列表方法。如何將分頁和排序參數添加到此查詢中?Grails:將排序和分頁添加到自定義HQL查詢
def list = {
def termList
log.info "Getting terms for product: $params.productId"
params.max = 10
def p = Product.get(params.productId)
if (p) {
log.info "Product found: $p.name"
termList = Term.executeQuery("select distinct t from Term as t join t.definitions def join def.definitionProducts dp where dp.product=?",
p)
} else {
log.info "No Product found"
termList = Term.list(params)
}
log.info "Terms found: $termList.size"
[ termInstanceList: termList, termInstanceTotal: termList.size]
}
這個答案ISN」完全正確。像下面的答案狀態一樣,您不能使用executeQuery進行排序和排序。見http://jira.codehaus.org/browse/GRAILS-1200。 – 2009-10-05 05:37:56