通过xml处理sql语句时对小于号与大于号的处理转换
当我们需要通过xml格式处理sql语句时,经常会用到< ,<=,>,>=等符号,但是很容易引起xml格式的错误,这样会导致后台将xml字符串转换为xml文档时报错,从而导致程序错误。
这样的问题在iBatiS中或者自定义的xml处理sql的程序中经常需要我们来处理。其实很简单,我们只需作如下替换即可避免上述的错误:
| 原符号 | < | <= | > | >= | & | ' | " |
| 替换符号 | < | <= | > | >= | & | ' | " |
错误格式如下:
<select id="fenye" parameterType="Map" resultMap="users">
select * from
<trim prefix="(" suffix=") b">
select a.*,rownum rn from
<trim prefix="(" suffix=") a">
select * from test t order by t.id desc
</trim>
<!-- <if test="size!=null">
rownum<=#{size}
</if> -->
</trim>
<where>
b.rn < #{size}
</where>
</select>
正确格式如下:
<select id="fenye" parameterType="Map" resultMap="users">
select * from
<trim prefix="(" suffix=") b">
select a.*,rownum rn from
<trim prefix="(" suffix=") a">
select * from test t order by t.id desc
</trim>
<!-- <if test="size!=null">
rownum<=#{size}
</if> -->
</trim>
<where>
b.rn < #{size}
</where>
</select>

浙公网安备 33010602011771号