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;
    }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM