Grails - user - HQL, criteria, pagination, and counts; grails hql 分页
//设置count查询字符串 比较神奇的地方时count(t)用对象也可以,用count(1)就报错了
StringBuilder selectCount = new StringBuilder("select count(t) ")
//设置内容查询字符串
StringBuilder selectData = new StringBuilder("select a.column1,a.column2 ")
//设置后续拼接字符串
StringBuilder sb=new StringBuilder(" from table t ")
/**查询结果列表 ,用closure接受分页,排序参数
*max: params.max 每页显示数目
*offset: (params.offset?params.offset:params.max) 开始查询条数,like fromIndex
*sort:params. sort ?params. sort :"columnSample" 排序字段
*order:params.order?params.order:"asc" 排序方式,asc\desc
**/
def result=CheckAttendance.executeQuery(selectData.append(sb).toString(),[max: params.max,
offset: (params.offset?params.offset:params.max),
sort:params. sort ?params. sort :"columnSample",
order:params.order?params.order:"asc"])
//查询总数
int total=(Integer)CheckAttendance.executeQuery(selectCount.append(sb).toString()).get(0)
问题:发现executeQuery不支持排序,所以只能用hql排序,那么查询总数只能放在排序的前面
int total=(Integer)CheckAttendance.executeQuery(selectCount.append(sb).toString()).get(0)
if (params.sort && params.order)
{
sb.append(" order by "+params.sort + " "+params.order)
}
感想:都是foreigners帮忙解决的,中文根本没用,万恶的世界最大局域网
相关推荐
hooopo 2014-07-12
80447518 2014-06-18
purpen 2014-05-23
jackyzhuyuanlu 2015-02-12
龙浩然 2015-11-06
daociyiyou 2016-11-07
coderbx 2013-03-11
yehell 2012-04-24
yeyedeyatou 2011-08-04
Ben的程序员生涯 2011-04-29
jieren 2010-02-18
carpenterworm 2009-04-03
trapeze 2008-06-06
掘井之路 2019-07-01