美文网首页
MyBatis中特殊符号的转义

MyBatis中特殊符号的转义

作者: 橙一万 | 来源:发表于2020-04-22 11:51 被阅读0次

在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>

相关文章

网友评论

      本文标题:MyBatis中特殊符号的转义

      本文链接:https://www.haomeiwen.com/subject/inabihtx.html