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') >= 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));
    
  • 相关阅读:
    P1099 [NOIP2007 提高组] 树网的核
    UVA 数学题选做
    Codeforces 729 Div.2
    P1600 [NOIP2016 提高组] 天天爱跑步
    CF1106F Lunar New Year and a Recursive Sequence
    P6091 【模板】原根
    P4774 [NOI2018] 屠龙勇士
    P1106 删数问题
    P1209 [USACO1.3]修理牛棚 Barn Repair
    网络(network)
  • 原文地址:https://www.cnblogs.com/aitree/p/14923720.html
Copyright © 2011-2022 走看看