MyBatis 和 ibatis的动态SQL语句配置符号,不兼容大于号、小于号等特殊符号有关问题

MyBatis 和 ibatis的动态SQL语句配置符号,不兼容大于号、小于号等特殊符号问题


在XML映射SQL的文件中,很多情况下会使用到大于号、小于号等特殊符号,这时候如果不进行控制是无法编译通过的,这时候需要用到<![CDATA[  ]]>符号进行说明,将此类符号不进行解析,其实,这个问题不止在MyBatis上通用,而是它通用于任何XML的文件中使用,比如Hibernate、Wabacus、Spring等等等等配置文件中,只要是XML文件就行,此类问题在以后的工作中,经常使用。


案例代码

<select id="findAllKiaAnalysisByCondition" parameterType="map" resultType="KiaAnalysis">
	select * from (select unitname, to_char(rdate,'yyyy-MM') rdate,keytype, scope from KIAANALYSIS 
		<where>
			<if test='startDate!="%null%"'> and rdate >= to_date(#{startDate},'yyyy-mm')</if>
			<if test='endDate!="%null%"'>
				<strong><span style="color:#3333ff;"><![CDATA[</span><span style="color:#3366ff;"> </span></strong>and rdate <= to_date(#{endDate},'yyyy-mm') <span style="color:#3333ff;"><strong>]]></strong></span>
			</if>
			<if test='unitname!="%null%"'>and unitname=#{unitName}</if>
		</where>
	) pivot (sum(scope) for keytype in(${themes}))
</select>