EBOARD_DATETIME 为DATE类型,startTime与endTime为String类型
方法一:
<where>
<trim>
<if test="productCode!= null and productCode!= ''">
and regexp_like(EBOARD_PRODUCTCODE ,#{productCode},'i')
</if>
<if test="productName!= null and productName!= ''">
and regexp_like(EBOARD_PRODUCTNAME ,#{productName},'i')
</if>
<if test="startTime!= null and startTime!= ''">
<if test="endTime!= null and endTime!= ''">
and EBOARD_DATETIME
BETWEEN
to_date(#{startTime},'yyyy-MM-DD hh24:mi:ss')
AND to_date(#{endTime},'yyyy-MM-DD hh24:mi:ss')
</if>
</if>
</trim>
</where>
方法二:
<where>
<trim>
<if test="productCode!= null and productCode!= ''">
and regexp_like(EBOARD_PRODUCTCODE ,#{productCode},'i')
</if>
<if test="productName!= null and productName!= ''">
and regexp_like(EBOARD_PRODUCTNAME ,#{productName},'i')
</if>
<if test="startTime!= null and startTime!= ''">
<![CDATA[ and EBOARD_DATETIME >= to_date(#{startTime},'yyyy-MM-dd HH24:MI:SS') ]]>
</if>
<if test="endTime!= null and endTime!= ''">
<![CDATA[ and EBOARD_DATETIME < to_date(#{endTime},'yyyy-MM-dd HH24:MI:SS')+1 ]]>
</if>
</trim>
</where>
<![CDATA[ ]]> 的作用是将【】内内容表示为纯文本
<![CDATA[ ]]>作用与转义字符相同
<![CDATA[ ]]> 表示xml解析器忽略解析,所以更快