【mybatis】in查询+判断list查询条件是否进行in查询

mybatis中的in查询: 并且判断in查询的list是否为null或者list有值才进行In查询

 <select id="find" parameterType="com.pisen.cloud.luna.ms.goods.base.domain.GoodsType" resultType="com.pisen.cloud.luna.ms.goods.base.domain.GoodsType">
        SELECT
            create_date createDate,
            uid uid,
            name name,
            py_all pyAll,
            py_head pyHead,
            outer_id outerId,
            outer_code outerCode,
            mnemonic_code mnemonicCode,
            enabled_flag enabledFlag,
            remark remark,
            parent_uid parentUid,
            tenement_id tenementId
        FROM
            goods_type
        WHERE
          tenement_id = #{tenementId}
        <if test="typeUidList != null and typeUidList.size() > 0">
            and
            (
            uid in
            <foreach collection="typeUidList" item="item" index="index" open="(" separator="," close=")">
                #{item}
            </foreach>
            OR
            parent_uid in
            <foreach collection="typeUidList" item="item" index="index" open="(" separator="," close=")">
                #{item}
            </foreach>
            )
        </if>

        <if test="name != null and name != '' ">
            and
              name like '%' #{name} '%'
        </if>

        <if test="outerCode != null and outerCode != '' ">
            and
            outer_code = #{outerCode}
        </if>

    </select>

 

posted @ 2018-05-28 19:57  Angel挤一挤  阅读(1593)  评论(1编辑  收藏  举报