多条件查询

<select id="selectByPrimaryKeySelective" parameterType="com.mjs.mojisishop.entity.OrderInfo"
            resultMap="orderInfoMap">
        select
        e1.id,e1.orderNo,e1.payType,e1.orderPrice,e1.orderStatus,e1.contacts,e1.phoneNum,e1.address,e1.expressName,e1.expressCode,
        e1.creatUser,e1.note,e1.creatTime,e1.lastTime,
        e2.id as oid,e2.orderNo as
        oorderNo,e2.discountCode,e2.itemId,e2.goodsName,e2.unitPrice,e2.amount,e2.totalPrice,e2.detailStatus,
        e2.creatUser as ocreatUser,e2.creatTime as ocreatTime,e2.lastTime as olastTime
        from `order` e1,order_detail e2
        where 1=1 and e1.orderNo=e2.orderNo
        <if test="orderno!=null and orderno!=''">
            and e1.orderNo like concat('%',#{orderno},'%')
        </if>
        <if test="orderstatus != null and orderstatus != ''">
            and orderStatus = #{orderstatus,jdbcType=INTEGER}
        </if>
        <if test="title != null and title != ''  ">
            and title like concat('%',#{title},'%')
        </if>
        <if test="creattime != null or  lasttime != null ">
            and e1.creatTime
            between #{creattime,jdbcType=TIMESTAMP} and
            #{lasttime,jdbcType=TIMESTAMP}
        </if>
         <!--查询可用优惠券时传creatTime,来比较validtime,&gt;=大于等于,&lt;=小于等于
        -->
        <if test="creatTime != null ">
            <!--<![CDATA[and validTime >= #{creatTime}]]>-->
            and validTime &gt;= #{creatTime}
        </if>
        <if test="validTime != null ">
            and validTime &lt; #{validTime}
        </if>
    </select>

注意if条件末尾不能有逗号

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值