0
点赞
收藏
分享

微信扫一扫

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

老牛走世界 2022-04-21 阅读 42

第一种

<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 条评论