Mybatis if標簽判斷大小


1、if標簽語法

<select...>
  SQL語句1
  <if test="條件表達式">
     SQL語句2
  </if>
</select>

注意:條件表達式中大於號小於號用 gt,lt

<if test="vane gt 0">...</if>

<if test="vane lt 0">...</if>

mapper xml代碼:

  <select id="selectByUpdatedAt" resultMap="ResultMapWithBLOBs">
    select
    <include refid="Base_Column_List" />
    ,
    <include refid="Blob_Column_List" />
    from products
    <where>
        <if test="vane gt 0">
            updated_at &gt; #{date} AND status = #{status}
            ORDER BY is_top desc , updated_at desc
        </if>
        <if test="vane == 0">
            updated_at = #{date} AND status != #{status}
            ORDER BY is_top desc , updated_at desc
        </if>
        <if test="vane lt 0">
            updated_at &lt; #{date} AND status = #{status}
            ORDER BY is_top desc , updated_at desc
        </if>

    </where>
  </select>

mapper 接口代碼:

/**
     * vane大於0表示大於;0表示等於;小於0表示小於;
     * status 商品狀態。1:在售;2:下架;3:刪除;
     * @param vane vane
     * @param date 時間
     * @param status 商品狀態
     * @return List
     */
    List<Product> selectByUpdatedAt(@Param("vane") Integer vane,
                                    @Param("date") Date date,
                                    @Param("status") Byte status);

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM