Mybatis查询日期范围
生活随笔
收集整理的這篇文章主要介紹了
Mybatis查询日期范围
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
查詢日期范圍
將日期時間,轉換為字符串
select s.* from BIZ_ASSAY_ORDER_SAMPLE s LEFT JOIN BIZ_ASSAY_ORDER o on o.ID=s.ORDER_ID WHERE 1=1 <if test="status !=null and status !=''">AND s.RECORD_STATUS=#{status} </if> <if test="sampleNo !=null and sampleNo !=''">AND s.SAMPLE_NO LIKE '%'||#{sampleNo}||'%' </if> <if test="orderNo !=null and orderNo !=''">AND o.ORDER_NO LIKE '%'||#{orderNo}||'%' </if> <if test="sampleBizModelId !=null and sampleBizModelId !=''">AND s.SAMP_BIZ_MODE_ID=#{ sampleBizModelId } </if> <if test="statusFlag !=null and statusFlag !=''">AND s.STATUS_FLAG=#{ statusFlag } </if> <if test="fromDate != null and fromDate !=''">and to_char(o.ORDER_DATE,'yyyy-MM-dd') >= #{fromDate} </if> <if test="toDate != null and toDate !=''">and to_char(o.ORDER_DATE,'yyyy-MM-dd') <= #{toDate} </if>關鍵代碼
<if test="fromDate != null and fromDate !=''">and to_char(o.ORDER_DATE,'yyyy-MM-dd') >= #{fromDate} </if> <if test="toDate != null and toDate !=''">and to_char(o.ORDER_DATE,'yyyy-MM-dd') <= #{toDate} </if>或者
將字符串,轉換為日期時間
SELECT <include refid="Base_Column_List"/> FROM BIZ_DAILY_PLAN dp LEFT JOIN DIC_TEST_OBJECT tb ON dp.TEST_OBJECT_ID=tb.ID LEFT JOIN DIC_SAMPLE_BIZ_MODEL bm ON dp.SAMP_BIZ_MODE_ID=bm.ID LEFT JOIN RES_LABORATORY l ON dp.LABORATORY_ID=l.ID WHERE 1=1 AND dp.RECORD_STATUS = ${@cn.com.hwasunsoft.lims.core.enums.RecordStatusEnum@VALID.getValue()} <if test="dailyPlanStatus !=null and dailyPlanStatus !=''">AND dp.CONFIRMATION_STATUS=#{dailyPlanStatus} </if> <if test="status !=null and status !=''">AND dp.RECORD_STATUS=#{status} </if> <if test="labId !=null and labId !=''">AND dp.LABORATORY_ID=#{labId} </if> <if test="fromDate !=null and fromDate !=''">AND dp.PLAN_DATE >= TO_DATE(#{fromDate},'yyyy-mm-dd') </if> <if test="toDate !=null and toDate !=''">AND TO_DATE(#{toDate},'yyyy-mm-dd') >= dp.PLAN_DATE </if>關鍵代碼
<if test="fromDate !=null and fromDate !=''">AND dp.PLAN_DATE >= TO_DATE(#{fromDate},'yyyy-mm-dd') </if> <if test="toDate !=null and toDate !=''">AND TO_DATE(#{toDate},'yyyy-mm-dd') >= dp.PLAN_DATE </if>日期等于某天
直接把大于、小于號,改為等于號
總結
以上是生活随笔為你收集整理的Mybatis查询日期范围的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Mybatis字段模糊查询
- 下一篇: Mybatis的selectKey使用