ibatis的sql配置檔案sql.xml大於小於等於的寫法
阿新 • • 發佈:2019-02-06
在ibatis的sql語句xml配置檔案中,寫sql語句會經常用到大於等於小於等於等等符號。網上搜羅了一些寫法,大致有3種:
-
其實就是xml特殊符號,轉義的方式。
<
<>
><>
<>&
&'
’"
”
比如:select (case when (UNIX_TIMESTAMP(now())-UNIX_TIMESTAMP(ur.offline_time)-5*60*1000)>0 then '1' else '0' end) as offline_flag from ……
-
使用
<![CDATA[ sql語句]]>
符號進行說明,將此類符號不進行解析 。
比如:<isEqual property="offline_flag" compareValue="0">
and <![CDATA[((UNIX_TIMESTAMP(now())-UNIX_TIMESTAMP(ur.offline_time)-5*60*1000)<=0 or u.record_id=0)]]>
</isEqual> -
如果是引數欄位,可以用ibatis的語法。
<isEqual> 相等。
<isNotEqual> 不等。
<isGreaterThan> 大於
<isGreaterEqual> 大於等於
<isLessThan> 小於
<isLessEqual> 小於等於
比如:<isNotEmpty prepend="AND" property="username">
u.username like '%$username$%'
</isNotEmpty>
<isNotEmpty prepend="AND" property="location">
concat(u.country,u.province,u.city) like '%$location$%'
</isNotEmpty>
<isEqual property="offline_flag" compareValue="1">
and (UNIX_TIMESTAMP(now())-UNIX_TIMESTAMP(ur.offline_time)-5*60*1000)>0
</isEqual>
<isEqual property="offline_flag" compareValue="0">
and <![CDATA[((UNIX_TIMESTAMP(now())-UNIX_TIMESTAMP(ur.offline_time)-5*60*1000)<=0 or u.record_id=0)]]>
</isEqual>
<!-- sort -->
<isEqual property="sort_onlinetime" compareValue="asc">
order by u.online_time asc
</isEqual>
<isEqual property="sort_onlinetime" compareValue="desc">
order by u.online_time desc
</isEqual>
<isEqual property="sort_registtime" compareValue="asc">
order by u.register_time asc
</isEqual>
<isEqual property="sort_registtime" compareValue="desc">
order by u.register_time desc
</isEqual>
<isEqual property="sort_appversion" compareValue="asc">
order by u.app_version asc
</isEqual>
<isEqual property="sort_appversion" compareValue="desc">
order by u.app_version desc
</isEqual>