Translation processing of SQL less than sign and greater than sign in mapper.xml

The sql written in the mapper mapping file of the Mybatis framework does not recognize the <,> symbols. The solution is to use special symbols to translate

< <= > >= &
&lt; &lt;= &gt; &gt;= &amp;
<![CDATA[ < ]]> <![CDATA[ <= ]]> <![CDATA[ > ]]> <![CDATA[ >= ]]> <![CDATA[ & ]]>

Case: Query the information of students whose grades are greater than or equal to 80

 
<select id="selectStudent" parameterType="com.lyj.domain.Student" resultMap="StudentMap">
    select
        <include refid="Base_Column_List"/>
    from link_student
    where 1=1
        <if test="student.score!= null">
           and score >= #{student.score}
        </if>
</select>

The > sign above is not compiled and needs to be processed with special symbols

<select id="selectStudent" parameterType="com.lyj.domain.Student" resultMap="StudentMap">
    select
        <include refid="Base_Column_List"/>
    from link_student
    where 1=1
        <if test="student.score!= null">
            and score &gt;= #{student.score}
        </if>
</select>
<select id="selectStudent" parameterType="com.lyj.domain.Student" resultMap="StudentMap">
    select
        <include refid="Base_Column_List"/>
    from link_student
    where 1=1
        <if test="student.score!= null">
            and score <![CDATA[ >= ]]> #{student.score}
        </if>
</select>

Guess you like

Origin blog.csdn.net/liyingjie2001/article/details/127925520