mybatis同时使用and和or

1.在when或if里边and拼接(),保持与其他条件不冲突

   <select id="selectUserWashOrderList" resultType="SwOrder">
        SELECT so.*,ss.store_name
        FROM sw_order so
        LEFT JOIN sw_store ss ON so.store_id = ss.id
        where ss.deleted = 0 AND so.order_type = 0 and so.user_id = #{query.user_id}
        <choose>
            <when test="query.waitPayStatus !=null">
                and (so.status = #{query.unSettled} or so.status = #{query.waitPayStatus})
            </when>
            <when test="query.waitPayStatus == null ">
                <if test="query.status !=null">
                    and so.status = #{query.status}
                </if>
            </when>
        </choose>
        order by so.created_at desc
        limit #{pageNum},#{pageSize}
    </select>

    <select id="selectUserWashOrderListCount" resultType="Integer">
        select count(*) from (
        SELECT so.*,ss.store_name
        FROM sw_order so
        LEFT JOIN sw_store ss ON so.store_id = ss.id
        where ss.deleted = 0 AND so.order_type = 0 and so.user_id = #{query.user_id}
        <choose>
            <when test="query.waitPayStatus !=null">
                and (so.status = #{query.unSettled} or so.status = #{query.waitPayStatus})
            </when>
            <when test="query.waitPayStatus ==null ">
                <if test="query.status !=null">
                    and so.status = #{query.status}
                </if>
            </when>

        </choose>
        order by so.created_at desc
        )c
    </select>

你可能感兴趣的:(java,mysql,spring,boot)