Mybatis中 的使用


Mybatis的sql是寫在xml映射文件中的,如果sql中有一些特殊的字符,在解析xml文件的時候會被轉義,使用<![CDATA[ ]]>就可以讓這些特殊字符不被轉義。

<![CDATA[ ]]>是xml的語法,放在CDATA[]內部的特殊字符都會被解析器忽略,所以在我們使用<if test=""></if><where>、</where><choose></choose><trim></trim>等標簽實現動態sql時,我們需要把sql語句中出現的<、<=、&等特殊符號都放在CDATA[]的內部

下面是實例:

    <update id="delData" parameterType="com.hx.pojo.BrowsingHistory">
        update td_browsing_history set status = '9'
        <where>
            browsing_user_id = #{browsingUserId}
            <if test="startTime != null ">
                and browsing_time <![CDATA[ >= ]]> #{startTime}
            </if>
            <if test="endTime != null ">
                and browsing_time <![CDATA[ <= ]]> #{endTime}
            </if>
            <if test="id != null and id != ''">
                and ID = #{id}
            </if>
        </where>
    </update>


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM