mybatis xml 关于查询一个时间区间写法

阅读 42

2022-04-21

第一种

<if test="startDate!=null and startDate!=''"> and CREATEDATE &gt;=#{startDate}</if>
<if test="endDate!=null and endDate!=''"> and CREATEDATE &lt;=#{endDate}</if>

ps:标签内的<、>需要转义
在这里插入图片描述

第二种

<if test="startDate != null and startDate !=''"><![CDATA[  and CREATEDATE >= #{startDate}]]></if>
<if test="endDate != null and endDate !=''"><![CDATA[  and CREATEDATE <= #{endDate} ]]></if>

ps:在XML中包含特殊字符的要用<![CDATA[ 内容]]>包裹起来 当成sql语句处理不需要转义

精彩评论(0)

0 0 举报