Java类中使用Date类型,而其映射文件使用java.sql.Timestamp类型,保存时即可保存为DateTime类型!
保存时:
Date today = Calendar.getInstance().getTime(); email.setCreateDate(today);
最后数据库中:
Date查询:
Date是String型:
String startdate = DateUtil.dateToStr(day, "@dd@@MMM@@yyyy@"); String enddate = DateUtil.dateToStr(oneDay, "@dd@@MMM@@yyyy@"); if(startdate!=null && !startdate.equals("") && enddate!=null && !enddate.equals("")){ String sb = ""; sb = "(startdate<='"+startdate+"' and enddate>='"+startdate+"')"; sb += " or (startdate<='"+enddate+"' and enddate>='"+enddate+"')"; sb += " or (enddate >='" + enddate + "' and '"+startdate+"' >= startdate)"; sb += " or (enddate <='" + enddate + "' and '"+startdate+"' <= startdate)"; detachedCriteria.add(Expression.sql(sb.toString())); }
或:
if(stayDateFrom!=null && !stayDateFrom.equals("")){ hql.append(" and hra.staydate >= '"+stayDateFrom+" 00:00:00'"); } if(stayDateTo!=null && !stayDateTo.equals("")){ hql.append(" and hra.staydate <= '"+stayDateTo+" 23:59:59'"); }
Date是日期类型:
if(markuplayerSpecialDay.getStartdate() != null && !"".equals(markuplayerSpecialDay.getStartdate())) detachedCriteria.add(Expression.ge("startdate", markuplayerSpecialDay.getStartdate())); if(markuplayerSpecialDay.getEnddate() != null && !"".equals(markuplayerSpecialDay.getEnddate())) detachedCriteria.add(Expression.le("enddate", markuplayerSpecialDay.getEnddate())); //markuplayerSpecialDay.getStartdate()为Date类型
。。。