zoukankan      html  css  js  c++  java
  • Mybatis和Mybatis-Plus时间范围查询,亲测有效

    一、mysql

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

     <if test="startTime!=null and startTime.trim() neq ''">
        and date_format(create_time,'%Y-%m-%d %H:%i:%s') &gt;= 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') &lt;= 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') &gt;= 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') &lt;= 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 (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));
    
  • 相关阅读:
    requests模块
    Html5五子棋
    html5学习之旅第一篇
    Vue.js学习和第一个实例
    electron安装到第一个实例
    mongodb学习-练习实例
    nosql学习一
    csv内存流文件流
    关于Vue中img的src属性绑定的一些坑
    java中的==操作符和equals函数
  • 原文地址:https://www.cnblogs.com/fly4j/p/12696234.html
Copyright © 2011-2022 走看看