寫原生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