mybatis根据时间检索查询


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

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

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

            <if test="beginTime != null and beginTime != ''">
                <!-- 开始时间检索 --> and date_format(receive_time,'%y%m%d') &gt;= date_format(#{beginTime},'%y%m%d') </if>
            <if test="endTime != null and endTime != ''">
                <!-- 结束时间检索 --> and date_format(receive_time,'%y%m%d') &lt;= 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


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM