我有一个域类Project,如下所示
class Project {
String projectName
String projectCode
String techLead
String projectManager
Date deliveryDate
String currentPhase
Integer priority
}
我有控制器如下
class ProjectController {
def scaffold = Project
def index = {
redirect(action:list,params:params)
}
def list = {
// displays only 10 records per page
if (!params.max) params.max = 10
[ projectList: Project.list( params ) ]
}
}
我想在排序顺序或优先级中显示项目列表。我该如何实现呢?
答案 0 :(得分:1)
将您的list
操作更改为以下
def list = {
// displays only 10 records per page
if (!params.max) {
params.max = 10
}
params.sort = "priority"
params.order = "asc" // change to "desc" to sort in the opposite direction
[projectList: Project.list(params)]
}
答案 1 :(得分:1)
更短且更惯用的方法是使用提供排序的list
上的动态方法:
def list = {
[projectList: Project.listOrderByPriority(max: params.max ?: 10)]
}