您的位置:首页 > 其它

mybatis中的<![CDATA[]]>用法

2018-02-06 13:39 696 查看
在使用mybatis时sql语句写在xml映射文件中,如果sql语句中包含一些特殊字符,在xml解析的时候就会被转义,所以要使用<![!CDATA[]]>来防止一些特殊的字符被转义。如果sql语句中包含"<"、">"、"&"特殊字符,sql语句最后放在<![CDATA[]]>中。但是<if test=""></test>、<where></where>、<choose>等标签不被解析,因此不要放在<![CDATA[]]>中。

<select id="countGourpByTenantId" parameterType="java.util.Date"
resultType="java.util.Map">
<![CDATA[
select lower(hex(tenant_id)) tenant_id,
count(case when date(create_time)= date(#{now,jdbcType=TIMESTAMP}) then 1 end) action_day,
count(case when year(create_time)= year(#{now,jdbcType=TIMESTAMP}) and month(create_time)= month(#{now,jdbcType=TIMESTAMP}) then 1 end) action_month,
count(*) action_all
from action
where tenant_id is not null
group by tenant_id
]]>
</select>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: