MyBatis中特殊符号的转义

在MyBatis中遇到特殊符号时有两种转义方式:

第一种

描述 空格 小于 大于 小于等于 大于等于 单引号 双引号
原符号 < > <= >= & ' "
替换符号 &nbsp; &lt; &gt; &lt;= &gt;= &amp; &apos; &quot;

例如:


<select id = "selectUserByAge" resultType="com.test.hiioc.model.UserTable" >
    select
        id,userName,age
    from
        userTable
    <where>
        IS_DELETE = 1
        /*时间段查询*/
        <if test = "userTable.startDate!=null">
            and SIGNING_DATE &gt;= #{userTable.startDate}
        </if>
        <if test = "userTable.endDate != null">
            and SIGNING_DATE &lt;= #{userTable.endDate}
        </if>
    </where>
</select>

第二种

使用 <![CDATA[>=]]> 进行转义

例如:


<select id = "selectUserByAge" resultType="com.test.hiioc.model.UserTable" >
    select
        id,userName,age
    from
        userTable
    <where>
        IS_DELETE = 1
        /*时间段查询*/
        <if test = "userTable.startDate != null">
            and SIGNING_DATE <![CDATA[>=]]> #{userTable.startDate}
        </if>
        <if test = "userTable.endDate!=null">
            and SIGNING_DATE <![CDATA[<=]]> #{userTable.endDate}
        </if>
    </where>
</select>

原文地址:https://www.cnblogs.com/orangebooks/p/11806513.html