Grails 查找具有特定分钟的条目
我有几个领域类每分钟生成大量数据集。像这样的事情:
class Foo{
String name
Date received
int value
}
我想完成此 MySQL 查询返回的相同结果集:
SELECT * FROM foo WHERE received BETWEEN ? AND ? AND MINUTE(received) = ?
这可以使用 NamedQuery 或 findAllBy... 吗?
谢谢。
I have several domain classes which generate large data sets each minute. Something like this:
class Foo{
String name
Date received
int value
}
I want to accomplish the same result set this MySQL query returns:
SELECT * FROM foo WHERE received BETWEEN ? AND ? AND MINUTE(received) = ?
Is this possible using a NamedQuery or findAllBy... ?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
嗯,由于HQL确实提供了微小的功能,所以我自己找到了解决方案。由于 Foo 是许多其他类的一部分,我想要一个适用于所有类的通用方法。无论如何,这是 Foo 和朋友们的解决方案:
无论如何,谢谢 Don。
Well, since HQL does provide a minute function, I was able to find a solution by myself. Since Foo is part of many other classes I wanted a common method for all of them. Anyway, here's the solution for Foo and friends:
Thanks anyway Don.
为了避免 HQL,您可以使用 sqlRestriction。但它不支持参数。
In order to avoid HQL, you can use sqlRestriction in a Criteria. It doesn't support parameters, though.