Mybatis日期類型的關系判斷
阿新 • • 發佈:2018-06-13
span != myba 使用 表示 關系運算符 AR art bsp
進行時間段的查詢時,在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>
解決方法有兩種,一種是使用">","<"來表示大於和小於關系,這樣,在解析時,這些特殊字符會被轉義成所匹配的運算符
<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>
另一種是使用"<![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>
Mybatis日期類型的關系判斷