有来技术官方博客,推荐关注微信公众|

有来技术

园龄:10年5个月粉丝:831关注:15

2020-04-14 10:22阅读: 34026评论: 0推荐: 3

Mybatis和Mybatis-Plus时间范围查询,亲测有效

一. MySQL

1. mapper.xml

 <if test="queryParams.beginTime!=null and queryParams.beginTime.trim() neq ''">
    and date_format(create_time,'%Y-%m-%d %H:%i:%s') >= date_format(#{queryParams.beginTime},'%Y-%m-%d %H:%i:%s')
  </if>
  <if test="queryParams.endTime!=null and queryParams.endTime.trim() neq ''">
    and date_format(create_time,'%Y-%m-%d %H:%i:%s') &lt;= date_format(#{queryParams.endTime},'%Y-%m-%d %H:%i:%s')
  </if>

2.Mybatis-Plus时间范围查询

 IPage<Record> result = iRecordService.page(new Page<>(pageNum, pageSize),
        new LambdaQueryWrapper<Record>()
            .apply(StrUtil.isNotBlank(beginDate),
                    "date_format (create_time,'%Y-%m-%d') >= date_format('" + beginDate + "','%Y-%m-%d')")
            .apply(StrUtil.isNotBlank(endDate),
                    "date_format (create_time,'%Y-%m-%d') <= date_format('" + endDate + "','%Y-%m-%d')")
            .orderByDesc(Record::getCreateTime()));

本文作者:有来技术

本文链接:https://www.cnblogs.com/haoxianrui/p/12696234.html

版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。

posted @   有来技术  阅读(34026)  评论(0编辑  收藏  举报
点击右上角即可分享
微信分享提示
评论
收藏
关注
推荐
深色
回顶
收起