您可以使用本机SQL查询
String sql = "SELECt * FROM tablename WHERe created_at > DATE_SUB(curdate(), INTERVAL 7 DAY)"Query query = session.createSQLQuery(sql);List result = query.list();
或者您可以使用Hibernate Criteria
Restrictions.sqlRestriction
String sqlWhere = "{alias}.created_at > DATE_SUB(curdate(), INTERVAL 7 DAY)";Criteria criteria = session.createCriteria(MyEntity.class);criteria.add(Restrictions.sqlRestriction(sqlWhere));List result = criteria.list();
希望能有所帮助。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)