Mybatis日期類型的關系判斷


進行時間段的查詢時,在mapper文件中直接使用">","<"等關系運算符是無法解析的

<if test="executeStartDate != null and executeStartDate != ''">
     and execute_time >= to_date(#{executeStartDate},'yyyy-MM-dd HH24:MI:SS')
</if>
<if test="executeEndDate != null and executeEndDate != ''">
     and execute_time <= to_date(#{executeEndDate},'yyyy-MM-dd HH24:MI:SS')
</if>

解決方法有兩種,一種是使用"&gt;","&lt;"來表示大於和小於關系,這樣,在解析時,這些特殊字符會被轉義成所匹配的運算符

<if test="executeStartDate != null and executeStartDate != ''">
      and execute_time &gt;= to_date(#{executeStartDate},'yyyy-MM-dd HH24:MI:SS')
</if>
<if test="executeEndDate != null and executeEndDate != ''">
      and execute_time &lt;= to_date(#{executeEndDate},'yyyy-MM-dd HH24:MI:SS')
</if>

另一種是使用"<![CDATA[   ]]>"來嵌套不需要轉義的內容

<if test="executeStartDate != null and executeStartDate != ''">
     and execute_time <![CDATA[>=]]> to_date(#{executeStartDate},'yyyy-MM-dd HH24:MI:SS')
</if>
<if test="executeEndDate != null and executeEndDate != ''">
     and execute_time <![CDATA[<=]]> to_date(#{executeEndDate},'yyyy-MM-dd HH24:MI:SS')
</if>

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM