Grails:标准生成器内的字段总和
在控制器中创建条件后,我不知道如何创建特定字段的运行总和
我当前正在使用以下方法创建一组记录:
def b = Tapes.createCriteria()
def yesterday = b.list(sort: 'migratedDate', order: 'asc') {
between ("migratedDate", dat.minus(1), dat)
}
计算该集中的项目数
def num2 = Tapes.countByMigratedDateBetween(dat.minus(1), dat)
并使用其中一个字段 在我的域中是“migeratedDuration”,系统返回进程的运行时间(以毫秒为单位)。控制器中有没有办法创建这个数字的总和?或者我应该通过相应的 .gsp 文件中的 javascript 来执行此操作?
再次感谢,
一个可怕的可怕的黑客
这完美地工作,谢谢
def todayTime = aa.list() {
between ("migratedDate", dat.minus(4), dat.minus(3))
projections { sum('migratedDuration')
}
}
I'm at a loss of how to create a running sum of particular field after creating a criteria within a controller
I'm currently creating a set of set of records using:
def b = Tapes.createCriteria()
def yesterday = b.list(sort: 'migratedDate', order: 'asc') {
between ("migratedDate", dat.minus(1), dat)
}
and counting the number of items in that set with
def num2 = Tapes.countByMigratedDateBetween(dat.minus(1), dat)
one of the fields in my domain is "migratedDuration", the system is returning the runtime of the process in milliseconds. Is there a way in the controller to create a sum of this number? Or should I have to do this via javascript in the corresponding .gsp file?
Thanks Again,
an awful awful hack
This worked perfectly, thanks
def todayTime = aa.list() {
between ("migratedDate", dat.minus(4), dat.minus(3))
projections { sum('migratedDuration')
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以为此使用投影:
可以找到可用投影的列表 这里。
You can use a projection for this:
A list of available Projections can be found here.
它真的是一个“运行总和”吗?即它是在每一行上递增还是您需要所有行的总和?
所有行的总和可以通过 Projection 来完成(阅读 CriteriaBuider 提供的“projections”闭包的 doco)。
如果是运行总计,则需要在控制器中执行此操作,或者在循环结果列表中的行时查看自己。
干杯
李
Is it truly a 'running sum' i.e. does it increment on each row or do you need the sum across all rows?
A sum across all rows can be done with a Projection (have a read of the doco for the "projections" closure provided by CriteriaBuider).
If it's a running total, you'll need to do that in the controller or view your self as you loop across the rows in the result list.
cheers
Lee