首页 > 其他 > 详细

Mybatis和Mybatis-Plus时间范围查询

时间:2021-06-23 20:48:30      阅读:27      评论:0      收藏:0      [点我收藏+]

一、mysql

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

 <if test="startTime!=null and startTime.trim() neq ‘‘">
    and date_format(create_time,‘%Y-%m-%d %H:%i:%s‘) >= str_to_date(#{startTime},‘%Y-%m-%d %H:%i:%s‘)
  </if>
  <if test="endTime!=null and endTime.trim() neq ‘‘">
    and date_format(create_time,‘%Y-%m-%d %H:%i:%s‘) <= str_to_date(#{endTime},‘%Y-%m-%d %H:%i:%s‘)
  </if>

2.传入时间范围参数类型是Date

 <if test="startTime!=null and startTime.trim() neq ‘‘">
    and date_format(create_time,‘%Y-%m-%d %H:%i:%s‘) >= date_format(#{startTime},‘%Y-%m-%d %H:%i:%s‘)
  </if>
  <if test="endTime!=null and endTime.trim() neq ‘‘">
    and date_format(create_time,‘%Y-%m-%d %H:%i:%s‘) <= date_format(#{endTime},‘%Y-%m-%d %H:%i:%s‘)
  </if>

3.Mybatis-Plus时间范围查询

 Page<Record> page = new Page<>(page, limit);
 IPage<Record> result = iRecordService.page(page,
        new LambdaQueryWrapper<Record>()
            .apply(StrUtil.isNotBlank(start_date),
                    "date_format (create_time,‘%Y-%m-%d‘) >= date_format(‘" + start_date + "‘,‘%Y-%m-%d‘)")
            .apply(StrUtil.isNotBlank(end_date),
                    "date_format (create_time,‘%Y-%m-%d‘) <= date_format(‘" + end_date + "‘,‘%Y-%m-%d‘)")
            .orderByDesc(HmsFaceDetectLog::getOptime));

 

Mybatis和Mybatis-Plus时间范围查询

原文:https://www.cnblogs.com/aitree/p/14923720.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!