用Mybayis(ibatis)设置时间段,排序。

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_41650354/article/details/82183860

假设前台传过来的开始时间: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);

}

猜你喜欢

转载自blog.csdn.net/qq_41650354/article/details/82183860