MyBatis中的if
<select id="getFiles" resultMap="BaseResultMap">
select * from files where status=1
<if test="size!=0">
and size=#{size}
</if>
order by id
</select>
MyBatis中没有else
(1)使用两个if
<select id="getFiles" resultMap="BaseResultMap">
select * from files where status=1
<if test="dealBigFiles == 0">
and size <= #{maxFileSize}
</if>
<if test="dealBigFiles != 0">
and size > #{maxFileSize}
</if>
order by id
</select>
(2)使用chose when otherwise
<select id="getFiles" resultMap="BaseResultMap">
select * from files where status=1
<choose>
<when test="dealBigFiles == 0">
and size <= #{maxFileSize}
</when>
<otherwise>
and size > #{maxFileSize}
</otherwise>
</choose>
order by id
</select>
标签:表示,files,else,status,MyBatis,where,id,size
From: https://blog.51cto.com/u_16271212/7772288