aks*_*hay 2 java hibernate hql date
我想找到所有映射到对象XYZ的记录,条件如下:A有日期字段XyzDateTime(它的时间戳)现在currentTime -xyzDateTime> 20我想选择记录
query = session.creatQuery(Select x from XYZ where :currentTime-xyzDateTime > 20 )
query.setParameter("currentTime",new Date())
Run Code Online (Sandbox Code Playgroud)
它是否正确?
我能用这种方式检查日期差异吗?
这不对.最简单的解决方案就是这样(根本不是最漂亮的解决方案)
Date twentyDaysInFuture = new Date(Calendar.getInstance().add(Calendar.DAY_OF_MONTH, 20).getTime());
query = session.createQuery("SELECT x FROM XYZ x WHERE xyzDateTime > :endDate").setParameter("endDate", twentyDaysInFuture);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5649 次 |
| 最近记录: |