MyBatis的if else表示

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 &lt;= #{maxFileSize}
            </if>
             <if test="dealBigFiles != 0">
                and size &gt; #{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 &lt;= #{maxFileSize}
            </when>
            <otherwise>
                and size &gt; #{maxFileSize}
            </otherwise>
        </choose>
        order by id
</select>

 

posted @ 2019-10-09 18:12  慕尘  阅读(6374)  评论(0编辑  收藏  举报