def list = {
try {
//通过传参params.domain,反射得到对应的domain
def domain = extUiService.getDomainClazz(params.domain)
//检证是否反射对应的domain
assert !!domain, "Domain Class with name ${params.domain} was not found!"
//获取开始读取数据的上限基数
def max = params.limit ? params.limit : 10
//获取开始读取数据的下限
def offset = params.start ? params.start : 0
//获取排序字段
def orderBy = params.sort ? params.sort : 'id'
//获取排序方式
def ascOrdesc = params.dir ? params.dir.toLowerCase() : 'asc'
//获取搜索字段
def likeBy = params.likeBy
//获取搜索字段对应的内容
def likeValue = params.likeValue
//获取搜索得到的所有数据
def totals = domain.withCriteria {
if(likeValue)
like(likeBy, "%" + likeValue + "%")
}
//获取分页数据
def items = domain.withCriteria {
firstResult(Integer.valueOf(offset))
maxResults(Integer.valueOf(max))
order(orderBy, ascOrdesc)
if(likeValue)
like(likeBy, "%" + likeValue + "%")
}
//构造返回数据结构
def result = [
total: totals.size(),
items: items
]
//转换为json返回数据
render (result as JSON).toString()
} catch(Throwable ex) {
onException(ex); return false
}
//当有异常时
return false;
}