mybatis根据时间检索查询


写原生sql虽然说麻烦,遇到问题排查的相对mybatis-plus也比较慢,但不得不说原生sql读写确实比较快,你要嫌写原生sql的代码量多的话也可以两者整合着写。

下面来说下mybatis对时间的检索查询,条件包括年、月、日。

1.时间段检索查询(两时间段)

            <if test="beginTime != null and beginTime != ''">
                
                and date_format(receive_time,'%y%m%d') >= date_format(#{beginTime},'%y%m%d')
            if>
            <if test="endTime != null and endTime != ''">
                
                and date_format(receive_time,'%y%m%d') <= date_format(#{endTime},'%y%m%d')
            if>

2.根据年、月查询

and date_format(create_at,'%Y-%m')=#{createAt}

3.根据年、月、日查询

and date_format(completion_time,'%y%m%d') = date_format(#{completionTime},'%y%m%d')

mybatis-plus篇

https://www.cnblogs.com/ckfeng/p/15667779.html