如何将 java.util.Calendar 和 HQL 结合起来
我正在尝试获取在两个日期之间借出的书籍。 由于数据有可爱的 2009 年显示为 109 个功能,我决定使用日历。
然而,在编写 HQL 时,我遇到了 BETWEEN 不将日历视为日期的问题。 现在我想知道是否有解决方案。 或者我是否一直在类中编写函数来获取小时、日、月、年并编写一个很长的 where 语句?
query = session.createQuery("from model.Book book where book.loaned Between :earliest and :latest");
问题是 Between 只适用于日期对象。借用的是Javva.Util.Calendar。
I'm trying to get the books that were loaned between two dates.
Since data has the lovely 2009 is shown as 109 feature I decided to use calendars.
However when writing my HQL I ran into the problem that BETWEEN doesn't view a Calendar as a date.
Now I'm wondering if there's a solution for this.
Or am I stuck writing functions in my class to get the hour, day, month, year and write a long where statement?
query = session.createQuery("from model.Book book where book.loaned between :earliest and :latest");
The problem is that the between only works with a date object. and loaned is Javva.Util.Calendar.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用
Calendar.getTime
从Calendar
获取Date
- 这对您有帮助吗?诚然,如果您不小心,您可能会遇到时区问题...数据库中存储的日期到底是如何的?You can get a
Date
from aCalendar
usingCalendar.getTime
- does that help you? You may run into time zone issues if you're not careful, admittedly... how exactly are the dates stored in the database?