根据Date比较数据库Date字段获取内容

//String转换Date 

DateFormat datef = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");  
Date date = datef.parse(cd);  


 
public Map getSmsContentByCateoryIdOrDate(Long id, Date date) {  
    Map<String,List> map = new HashMap<String,List>();  
    final String hq1 = "from SmsContent s where s.category.id="+id+" and s.deleteTime>:expTime";  
    final String hq2 = "from SmsContent s where s.category.id="+id+" and s.updateTime>:expTime";  
    final String hq3 = "from SmsContent s where s.category.id="+id+" and s.creationTime>:expTime";  
    map.put("deletedContentList",getListByName(hq1,date));  
    map.put("updatedContentList",getListByName(hq2,date));  
    map.put("addedContentList",getListByName(hq3,date));  
    map.put("allContentList",null);  
    return map;  
}  

//根据参数名返回List  
private List getListByName(final String hql,final Date date){  
    List list = (List)this.getHibernateTemplate().execute(new HibernateCallback() {  
        public Object doInHibernate(Session session) throws HibernateException, SQLException {  
        return session.createQuery(hql).setTimestamp("expTime",date).list();  
        }  
    });  
    return list;  
}  


//根据两个时间来获取数据 

public List statisticsSmsContentByDate(final Date beginDate,final Date endDate) {  
       return (List)this.getHibernateTemplate().execute(new HibernateCallback() {  
            public Object doInHibernate(Session session) throws HibernateException, SQLException {  
               return session.createCriteria(SmsContent.class).add(Restrictions.ge("creationTime",beginDate))  
                        .add(Restrictions.lt("creationTime",endDate)).list();  
                //session.createQuery("ssss :begin :end").setTimestamp().list();  
            }  
        });            
    }  

  

posted @ 2013-09-13 17:56  暖流  阅读(344)  评论(0编辑  收藏  举报