zoukankan      html  css  js  c++  java
  • 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);
  • 相关阅读:
    逆波兰表达式解数学运算(c#)
    杂文
    WebDriverExtensionsByC#
    cookie使用
    Discuz
    重构中学习
    生活知识
    js和 jquery对象
    jquery中is的用法
    html下select追加元素,IE下错误
  • 原文地址:https://www.cnblogs.com/xxoome/p/7211018.html
Copyright © 2011-2022 走看看