0
点赞
收藏
分享

微信扫一扫

MyBatis的if else表示

前行的跋涉者 2023-10-09 阅读 45

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>

举报

相关推荐

0 条评论