首页 > 其他 > 详细

Mybatis if标签判断大小

时间:2017-07-20 14:59:15      阅读:739      评论:0      收藏:0      [点我收藏+]

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);

 

Mybatis if标签判断大小

原文:http://www.cnblogs.com/xxoome/p/7211018.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!