hibernate使用日期查询,查询年月日,不要时间

大于,小于,等于,大于等于,小于等于

 public List<实体类> getBetweenStartDateAndEndDate(
            Session session, int id, DateTime startDateTime, DateTime endDateTime) {
        DateTime endDate = endDateTime.plusDays(1);//查询日期必须要加1天,不然查不到今天创建的记录,要考虑23:59:59秒的问题
        StringBuffer hql = new StringBuffer(
                "FROM 实体类 WHERE poolid = '" + id + "' AND createDt >= '"
                + startDateTime.toString("yyyy-MM-dd") + "' AND createDt <'"
                + endDate.toString("yyyy-MM-dd") + "' ORDER BY id ASC");
        Query query = session.createQuery(hql.toString());
        List<实体类> cps = query.list();
        return cps;
    }

 

posted @ 2020-09-10 17:15  不打鱼光晒网  阅读(808)  评论(0)    收藏  举报