问题:进行时间段的查询时,在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>
第1种解决方式
使用">","<"来表示大于和小于关系,这样,在解析时,这些特殊字符会被转义成所匹配的运算符
<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>
第2种解决方式
<![CDATA[ ]]>是XML语法,在CDATA内部的所有内容都会被解析器忽略,如果文本包含了很多的"<“字符 <=和”&"字符,那么把他们放到CDATA中,<![CDATA[ ]]>作用是嵌套不需要转义的内容<if test="executeStartDate != null and executeStartDate != ''">
and execute_time <![CDATA[>=]]> to_date(#{executeStartDate},'yyyy-MM-dd')
</if>
<if test="executeEndDate != null and executeEndDate != ''">
and execute_time <![CDATA[<=]]> to_date(#{executeEndDate},'yyyy-MM-dd')
</if>
第3种解决方式
<if test="executeStartDate != null and executeStartDate != ''">
<![CDATA[ and execute_time >= to_date(#{executeStartDate},'yyyy-MM-dd') ]]>
</if>
<if test="executeEndDate != null and executeEndDate != ''">
<![CDATA[ and execute_time <= to_date(#{executeEndDate},'yyyy-MM-dd') ]]>
</if>
版权声明:本文为weixin_40964170原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。