假设前台传过来的开始时间:startTime 结束时间:endTime
ServicePaymentRecordExample example = new ServicePaymentRecordExample();
ServicePaymentRecordExample.Criteria criteria = example.createCriteria();
//用他们mybitis(ibatis)自带的时间方法进行比较
if (MyUtils.isStrNotEmpty(this.startTime)){
criteria.andGmtCreateTimeGreaterThanOrEqualTo(MyUtils.changeTime(startTime + "00:00:00"));
}
if (MyUtils.isStrNotEmpty(this.endTime)){
criteria.andGmtCreateTimeLessThanOrEqualTo(MyUtils.changeTime(endTime+ "23:59:59"));
}
// 用他们mybitis(ibatis)自带的排序方法进行排序
example.setOrderByClause(" gmt_create_time DESC'); //里面放的是sql语句
//判断字符串不为空方法
public static boolean isStrNotEmpty(String str) {
return (str != null && !"".equals(str.trim()));
}
//转换时间格式
public static Date changeTime (String date) throws parseException {
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
return format.parse(date);
}