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>
<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>
相关文章推荐
- mybatis 的<![CDATA[ ]]>
- mybatis 中的<![CDATA[ ]]>
- Mybatis 中的<![CDATA[ ]]>浅析
- mybatis 中的<![CDATA[ ]]>
- mybatis 中的<![CDATA[ ]]>防止转义xml中特殊字符
- mybatis 中的<![CDATA[ ]]>
- mybatis 中的<![CDATA[ ]]>
- mybatis的sql的xml的配置文件中<![CDATA[ ]]>的用法。
- mybatis中的<![CDATA[ <> ]]>
- mybatis 中的<![CDATA[ ]]>
- mybatis中的<![CDATA[ <> ]]>
- Mybatis中的<association>用法
- mybatis中的xml文件中的特殊转义字符处理(<[!CDATA[]]>的用法)
- Mybatis中的<association>用法
- <![CDATA[]]>和转义字符 (注:这篇文章是本人在其他地方看到的,刚好项目中mybatis用到了,所以转来分享)
- Mybatis中的<![CDATA[ ]]>语法
- Mybatis 中的<![CDATA[ ]]>
- mybatis 中的<![CDATA[ ]]>
- mybatis 中的<![CDATA[ ]]>
- mybatis 中的<![CDATA[ ]]>