mapper.xml中特殊符号的转义

在使用 MyBatis 的 mapper.xml 文件中编写 SQL 时,需要注意比较符号的转义。错误的写法可能导致语法错误,例如在时间比较中直接使用 < 符号会导致问题。正确的做法是将比较符号转义为 &amp;lt;。本文详细介绍了如何正确转义 SQL 中的比较操作符,包括 &lt;, &gt;, &le;, &ge;, &amp; 和其他特殊字符。
摘要由CSDN通过智能技术生成

在使用mapper.xml编写sql语句的时候,我们经常会使用到比较符号,此时不可以像往常一样直接进行使用,需要进行转义,转义参考规则如:

 

<<=>>=&"
&lt; &lt;=&gt;&gt;=&amp;&apos;&quot;

 

 

例如常见的时间比较:

错误写法

 

 

<select id="select" parameterType="xxx" resultMap="xxx">

    select
        distinct
        <include refid="Base_Column_List" />
    from xxx
    <where>
        <if test="createDate != null">
            create_date <= #{createDate}
        </if>
    </where>
</select>

​ 正确写法

<select id="select" parameterType="xxx" resultMap="xxx">
    select
        distinct
        <include refid="Base_Column_List" />
    from xxx
    <where>
        <if test="createDate != null">
            create_date &lt;= #{createDate}
        </if>
    </where>
</select>
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值