上图是官方指导的一部分,主要说明了,在test中无法使用<= 等符号可以使用 lte 代替。
运算符 | 代替字符 |
---|---|
< | lt |
<= | lte |
> | gt |
>= | gte |
mybatis if test动态sql语句
<select id="getStudentId" parameterType="java.lang.String" resultType="java.lang.String"> ? ? ? ? SELECT MAX(Student_ID) FROM Student ? ? ? ? <where> ? ? ? ? ? ? <if test="classid !=null and classid !=''"> ? ? ? ? ? ? ? ? ? AND CLASS_ID = {student.classID}? ? ? ? ? ? ? </if> ? ? ? ? ? ? <if test="age ==null or age ==''"> ? ? ? ? ? ? ? ? ? AND AGE = {student.age} ? ? ? ? ? ? </if> ? ? ? ? </where> </select>
以上为个人经验,希望能给大家一个参考,也希望大家多多支持。