mybatis-plus
QueryWrapper<Object> queryWrapper = new QueryWrapper<>();
构造条件(查询某天)
queryWrapper.apply("date_format(completion_time,'%y%m%dd')=" + "date_format('" + transaction.getCompletionTime() + "','%y%m%dd')");
查询某月的数据
if (StringUtils.isNotEmpty(withdrawRecord.getCreateAt())) { queryWrapper.apply(" date_format(create_at,'%y%mm%') = date_format('" + withdrawRecord.getCreateAt() + "-01','%y%mm%')"); }
获取相隔两日之间的数据
if (StringUtils.isNotEmpty(orders.getBeginTime()) && orders.getBeginTime() != "") { wrapper.apply("date_format(create_time,'%y%m%d') >= date_format('" + orders.getBeginTime() + "','%y%m%d')"); } if (StringUtils.isNotEmpty(orders.getEndTime()) && orders.getEndTime() != "") { wrapper.apply("date_format(create_time,'%y%m%d') <= date_format('" + orders.getEndTime() + "','%y%m%d')"); }
mybatis一样的
<if test="beginTime != null and beginTime != ''"><!-- 开始时间检索 --> and date_format(create_time,'%y%m%d') >= date_format(#{beginTime},'%y%m%d') </if> <if test="endTime != null and endTime != ''"><!-- 结束时间检索 --> and date_format(create_time,'%y%m%d') <= date_format(#{endTime},'%y%m%d') </if>
其中beginTime为开始时间, endTime为结束时间, 传值类一定要有。