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
< | <= | > | >= | & |
< | <= | > | >= | & |
<![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 >= #{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>