一、概述
平时在mybatis的映射文件写sql时,很多时候都需要写一些特殊的字符。例如:"<" 字符 “>” 字符 “>=” 字符 “<=” 字符,但是在xml文件中并不能直接写上述列举的字符,否则就会报错。
因为在解析xml文件时候,我们如果书写了特殊字符,在没有特殊处理的情况下。这些字符会被转义,但我们并不希望它被转义,所以我们要使用<![CDATA[ ]]>来解决。在CDATA内部的所有内容都会被解析器忽略。所以,当我们在xml文本中包含了很多的"<" 字符 “<=” 和 “&” 字符—就像程序代码一样,那么最好把他们都放到CDATA部件中。
案例
<update id="updateTblCostVisualOrgnameInterface" parameterType="TblCostVisualOrgnameInterface">
update tbl_cost_visual_orgname_interface
<trim prefix="SET" suffixOverrides=",">
<if test="orgName != null">org_name = #{orgName},</if>
<if test="orgCode != null">org_code = #{orgCode},</if>
<!-- <if test="roleA != null">role_a = #{roleA},</if>-->
<!-- <if test="roleB != null">role_b = #{roleB},</if>-->
<if test="createBy != null">create_by = #{createBy},</if>
<if test="createTime != null">create_time = #{createTime},</if>
<if test="updateBy != null">update_by = #{updateBy},</if>
<if test="updateTime != null">update_time = #{updateTime},</if>
<if test="nameA != null"> <![CDATA[ role_a = JSON_SET(role_a, '$[0].name', #{nameA}), ]]></if>
<if test="OAA != null"><![CDATA[role_a = JSON_SET(role_a, '$[0].OA', #{OAA}), ]]></if>
<if test="phoneA != null"><![CDATA[role_a = JSON_SET(role_a, '$[0].phone', #{phoneA}), ]]></if>
<if test="deptA != null"><![CDATA[role_a = JSON_SET(role_a, '$[0].dept', #{deptA}) ]]></if>
</trim>
where id = #{id}
</update>