首页 > 代码库 > mybatis xml中特殊字符处理

mybatis xml中特殊字符处理

1,CDATA区:

它的全称为character data,以"<![CDATA[ "开始,以" ]]>" 结束,在两者之间嵌入不想被解析程序解析的原始数据,解析器不对CDATA区中的内容进行解析,而是将这些数据原封不动地交给下游程序处理。

2,特殊字符 :

xml 中表示:   <= 小于等于、    >= 大于等于 需加  这样的标记:     <![CDATA[   ]]>      xml中有&的符号,需要

<![CDATA[&]]>这样表示&

<= 小于等于 :<![CDATA[ <= ]]>

>= 大于等于:<![CDATA[  >=  ]]>

3,一些特殊字符也可用下面的替代符号所代替。

 特殊字符   替代符号

     &            &amp;

     <            &lt;

     >            &gt;

     "             &quot;

     ‘              &apos;

 

 1 <select id="exportBankChangeExcel" parameterType="Map" resultType="hashmap">
 2       select
 3           r.id,
 4           r.usermobile,
 5           v1.LoginName,
 6           v1.grade,
 7           (select count(*) from dl_account_relegation where to_usermobile = r.usermobile) accountType,
 8             <![CDATA[(CONCAT("户名:",r.realname," 卡号:",r.bank1," 银行:",REPLACE(r.bank2, "&", " 开户网点:")))]]> oldBank,
 9             <![CDATA[(CONCAT("户名:",r.new_realname," 卡号:",r.new_bank1," 银行:",REPLACE(r.new_bank2, "&", " 开户网点:")))]]> newBank,
10           u.real_name operateName,
11           u.create_time,
12           r.status
13         from dl_bank_record r
14           left join dl_vip v1
15             on r.usermobile = v1.usermobile
16             left join admin_user u
17             on u.xid = r.operate_user
18             where r.status = 0
19       <if test="startTime != null and startTime != ‘‘ ">
20         <![CDATA[
21         and r.create_time > #{startTime}
22         ]]>
23     </if>
24     <if test="endTime != null and endTime != ‘‘ ">
25         <![CDATA[
26         and r.create_time < #{endTime}
27         ]]>
28     </if>
29     <if test="operateUser != null and operateUser != ‘‘ ">
30         and u.xid = #{operateUser}
31     </if>
32     <if test="realName != null and realName != ‘‘ ">
33         and v1.realname = #{realName}
34     </if>
35     <if test="loginName != null and loginName != ‘‘ ">
36         and v1.LoginName = #{loginName}
37     </if>
38     <if test="usermobile != null and usermobile != ‘‘ ">
39         and v1.usermobile = #{usermobile}
40     </if>
41     <if test="phone != null and phone != ‘‘ ">
42         and v1.tel = #{phone}
43     </if>
44     order by r.change_time desc
45   </select>

 

mybatis xml中特殊字符处理