MyBatis中的ifselect 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)使用两个ifselect id="getFiles" resultMap="BaseResultM
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>
【本文来自:美国大带宽服务器 http://www.558idc.com/mg.html提供,感恩】