当我们需要通过xml格式处理sql语句时,经常会用到< ,<=,>,>=等符号,但是很容易引起xml格式的错误,这样会导致后台将xml字符串转换为xml文档时报错,从而导致程序错误。
这样的问题在iBatiS中或者自定义的xml处理sql的程序中经常需要我们来处理。其实很简单,我们只需作如下替换即可避免上述的错误:
原符号 | < | <= | > | >= | & | ' | " |
替换后 | < | <= | > | >= | & | ' | " |
<!--根据广告id获得所有的广告统计信息-->
<select id="selectAdvertCountList" resultType="aliasesPromAdvertCount">
select * from prom_advert_count WHERE 1=1
<if test="advertId!=null and advertId!=0">
and advertId=#{advertId}
</if>
<if test="advertType!=null and advertType!=0">
and advertType=#{advertType}
</if>
<if test="startTime!=null and startTime!=''">
and creationTime >= #{startTime}
</if>
<if test="endTime!=null and endTime!=''">
and creationTime <= #{endTime}
</if>
order by creationTime DESC
</select>