Mybatis和Mybatis-Plus时间范围查询方式

一、mysql 1.传入时间范围参数类型是字符串

and date_format(create_time,'%Y-%m-%d %H:%i:%s') > = str_to_date(#{startTime},'%Y-%m-%d %H:%i:%s')and date_format(create_time,'%Y-%m-%d %H:%i:%s') < = str_to_date(#{endTime},'%Y-%m-%d %H:%i:%s')

2.传入时间范围参数类型是Date
and date_format(create_time,'%Y-%m-%d %H:%i:%s') > = date_format(#{startTime},'%Y-%m-%d %H:%i:%s')and date_format(create_time,'%Y-%m-%d %H:%i:%s') < = date_format(#{endTime},'%Y-%m-%d %H:%i:%s')

3.Mybatis-Plus时间范围查询
Page page = new Page<>(page, limit); IPage result = iRecordService.page(page,new LambdaQueryWrapper().apply(StrUtil.isNotBlank(start_date),"date_format (optime,'%Y-%m-%d') >= date_format('" + start_date + "','%Y-%m-%d')").apply(StrUtil.isNotBlank(end_date),"date_format (optime,'%Y-%m-%d') <= date_format('" + end_date + "','%Y-%m-%d')").orderByDesc(HmsFaceDetectLog::getOptime));

Mybatis Plus 时间查询无效 错误写法
DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); QueryWrapper query = new QueryWrapper(); query.ge("create_time", LocalDateTime.parse("2019-05-13 23:00:00", df));

正确写法
query.apply("UNIX_TIMESTAMP(create_time) >= UNIX_TIMESTAMP('" + "2019-05-12 03:00:00" + "')");

【Mybatis和Mybatis-Plus时间范围查询方式】以上为个人经验,希望能给大家一个参考,也希望大家多多支持脚本之家。

    推荐阅读