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

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') <= date_format(#{queryParams.endTime},'%Y-%m-%d %H:%i:%s')
  if>

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()));

你可能感兴趣的:(#,Mybatis,mybatis,java,开发语言)