天天看點

MyBatis mapper.xml中SQL處理小于号與大于号 和小于等于号

這種問題在xml處理sql的程式中經常需要我們來進行特殊處理。

     其實很簡單,我們隻需作如下替換即可避免上述的錯誤:

<

<=

>

>=

&

'

"

<

<=

>

>=

&

'

"

例如常見的時間比較:

錯誤寫法

[html] view plain copy

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

     正确寫法

            create_date <= #{createDate}