-

首先要将条件 转换为 时间戳

  1. long startTime = TimeUtil.parseTimestamp(start);
  2. long endTime = TimeUtil.parseTimestamp(end);
  3. /*对应工具类*/
  4. public static long parseTimestamp(String datetime){
  5. try{
  6. SimpleDateFormat dateformat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  7. Date date = dateformat.parse(datetime);
  8. return date.getTime()/1000;
  9. }catch(Exception e){
  10. e.printStackTrace();
  11. }
  12. return 0;
  13. }

然后Mapper.xml中  使用BETWEEN and  和 to_timestamp

  1. <if test="startDate !=null and startDate !='' and endDate !=null and endDate !=''">
  2. AND tdnm.create_time BETWEEN to_timestamp(#{startDate}) AND to_timestamp(#{endDate})
  3. </if>